I need to get the difference of two SUM...WHERE
queries from the same table join:
SELECT SUM(Service_template.Service_fee)
FROM (Service_template LEFT JOIN Service ON Service_template.Service_Code = Service.Service_Code) LEFT JOIN Bill ON Service.Service_ID = Bill.Service_ID
WHERE Bill.Service_ID IS NOT NULL
and
SELECT SUM(Service_template.Service_fee)
FROM (Service_template LEFT JOIN Service ON Service_template.Service_Code = Service.Service_Code) LEFT JOIN Bill ON Service.Service_ID = Bill.Service_ID
I've tried using UNION
, but it returns two rows, not two columns I can make calculations on.
How do I go about doing it? I feel I am missing something trivial, so thanks in advance!