您好我有以下SQL查询
Select catalogid , numitems, allitems - numitems ignoreditems
from (
select i.catalogid,
sum(case when (ocardtype in ('PayPal','Sofort') OR
ocardtype in ('mastercard','visa') and
odate is not null) then numitems
else 0 end) numitems,
sum(numitems) allitems
from orders o
join oitems i on i.orderid=o.orderid
join products T1 on T1.catalogid = i.catalogid
group by i.catalogid
) X
在最后一个连接语句表中产品包含8列并且它们没有显示在结果查询中,我只能看到列catalogid,numitems和ignoreditems,所以我做错了,如果我必须选择那些列为了使它们出现我怎么能用这种语法来做呢?
答案 0 :(得分:1)
Select catalogid , numitems, allitems - numitems ignoreditems, X.c1,X.c2,X.c3,X.c4,X.c5,X.c6,X.c7,X.c8
from (
select i.catalogid,
sum(case when (ocardtype in ('PayPal','Sofort') OR
ocardtype in ('mastercard','visa') and
odate is not null) then numitems
else 0 end) numitems,
sum(numitems) allitems ,
T1.c1, T1.c2, T1.c3, T1.c4, T1.c5, T1.c6, T1.c7, T1.c8
from orders o
join oitems i on i.orderid=o.orderid
join products T1 on T1.catalogid = i.catalogid
group by i.catalogid, T1.c1, T1.c2, T1.c3, T1.c4, T1.c5, T1.c6, T1.c7, T1.c8
) X
答案 1 :(得分:1)
您只是查询这三列。如果希望产品中的列显示在结果集中,只需将它们添加到select语句即可。您可以逐个添加它们,或者只添加T1。*来查询所有这些:
Select catalogid , numitems, allitems - numitems ignoreditems, X.columnName1, X.ColumnName2, X.*
from (
select i.catalogid,
sum(case when (ocardtype in ('PayPal','Sofort') OR
ocardtype in ('mastercard','visa') and
odate is not null) then numitems
else 0 end) numitems,
sum(numitems) allitems,
-- This
T1.ColumnName1, T1.ColumName2, ...
--- or this way
T1.*
from orders o
join oitems i on i.orderid=o.orderid
join products T1 on T1.catalogid = i.catalogid
group by i.catalogid
) X