have the following sql query
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
now i've 2 tables Here orders and oitems table
the query sums the numitems
and ignoreditems
based on the conditions you see, now what if i want to find the sum only when the value of a column called oprocessed
in oitems
table is 0
,
do i add the following before X
where oprocessed=0
or should i add a condition to the SELECT CASE?