私はSQLを初めて使用し、次の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) AND NOT EXISTS (select CAST(booked AS INT) FROM bookedordersids b where b.booked = o.orderid)
then numitems
else 0 end) numitems,
sum(numitems) allitems
from orders o
join oitems i on i.orderid=o.orderid
group by i.catalogid
) X
そしてそれは私に次のエラーを与えます
Cannot perform an aggregate function on an expression containing an aggregat or a subquery
次の行を削除すると正常に動作します
AND NOT EXISTS (select CAST(booked AS INT) FROM bookedordersids b where b.booked = o.orderid)
ただし、このチェックを行うことが重要です。どうすればこれを修正できますか?