I am trying to sum-aggregate conditional products for total weight of an order (I hope that makes sense). I get error:
ERROR: aggregate function calls cannot be nested
LINE 6: , SUM ( CASE WHEN pc.type = 'TEES' THEN (SUM (opd.qt...
This is query excerpt:
SELECT DISTINCT
o.work_order_number dn
, SUM(opd.qty) units
, SUM (CASE WHEN pc.type = 'TEES' THEN (SUM (opd.qty) * .75)
WHEN pc.type = 'JERSEYS' THEN (SUM (opd.qty) * 1.5)
END) AS weight