Answer the question
In order to leave comments, you need to log in
How to sum columns?
SELECT
SUM(CASE WHEN c.status = 'confirmed'::incident_status THEN 1 END) as confirmed_ones,
SUM(CASE WHEN c.status = 'rejected'::incident_status THEN 1 END) as rejected_ones
FROM complaints AS c
WHERE c.user_id =21
AND NOT c.is_deleted
UNION
SELECT
SUM(CASE WHEN vr.status = 'confirmed'::incident_status THEN 1 END) as confirmed_ones,
SUM(CASE WHEN vr.status = 'rejected'::incident_status THEN 1 END) as rejected_ones
FROM violation_requests AS vr
WHERE vr.user_id = 21
AND NOT is_deleted;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question