I have the following sql tables
oitems table
+---------+-----------+----------+
| orderid | catalogid | numitems |
+---------+-----------+------
Something like:
SELECT
oi.catalog_id,
SUM(CASE
WHEN ocardtype in ('Paypal','Sofort') THEN numitems
WHEN ocardtype in ('Mastercard','Visa') and odate is not null THEN numitems
ELSE 0 END) as numitems,
SUM(CASE
WHEN ocardtype is null then numitems
WHEN ocardtype in ('Mastercard','Visa') and odate is null THEN numitems
ELSE 0 END) as ignoreditems
FROM
oitems oi
inner join
Orders o
on
oi.orderid = o.orderid
GROUP BY
oi.catalog_id
(Assuming that wherever you've used the word "empty" in your narrative, you mean the column is NULL
)