有以下sql查询
select catalogid
, sum(numitems) numitems
, sum(allitems) - sum(numitems) ignoreditems
from
(
select i.catalogid
, case
when (ocardtype in ('PayPal','Sofort') OR
ocardtype in ('mastercard','visa') and
odate is not null)
AND NOT EXISTS
(
select *
FROM bookedordersids b
where b.booked = o.orderid
)
then numitems
else 0
end AS numitems
, numitems AS allitems
from orders AS o
join oitems AS i on i.orderid = o.orderid
) AS X
group by catalogid
现在我有 2 个表,这里有订单和 oitems 表
查询根据您看到的条件对numitems
和求和ignoreditems
,现在如果我只想在表中调用的列的值为 时oprocessed
找到oitems
总和0
,
我之前要添加以下内容吗X
where oprocessed=0
或者我应该在 SELECT CASE 中添加一个条件?