0
有下面的SQL查詢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?
「現在如果我想找到總和......」。要檢查,你指的是哪一個數 - 構成被忽略的項目的總和,numitems的總數(這會影響被忽略的),還是其他的數字/結果? – JohnLBevan
當oprocessed是0我想要忽略它在這兩個總和 – user1570048
你想所有的價值也受到影響? – JohnLBevan