Postgres Sum Support StackOverflow
SELECT sum(CASE event
WHEN 'received' THEN
quantity
WHEN 'sent' THEN
-quantity
ELSE
0
END)
FROM shipments;
Puzzled Puffin