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;
Ответ получается:
============== ==============
confirmed_ones | rejected_ones |
=============== =============
1000 | 3 |
5002 | 2 |
Как сделать так чтобы получилось
confirmed_ones rejected_ones
6002 5