Goal: Find the count of uniques and duplicates in the worker_ref_id
column.
I find the solution here in MySQL but IF
does not exist in PostgreSQL. So, how would I do that in PostgreSQL?
I have the following table:
|worker_ref_id|bonus_amount|
| 1| 5000|
| 2| 3000|
| 3| 4000|
| 1| 4500|
| 2| 3500|
I would like the following output:
|Unique|Duplicates|
|1 |2 |
I get the right answer but it appears as two rows rather than two columns and one row:
SELECT COUNT(*) AS "Duplicate" FROM (SELECT worker_ref_id,
COUNT(worker_ref_id) AS "Count"
FROM bonus
GROUP BY worker_ref_id
HAVING COUNT(worker_ref_id) > 1) AS mySub
UNION
SELECT COUNT(*) AS "Unique" FROM (SELECT worker_ref_id,
COUNT(worker_ref_id) AS "Count"
FROM bonus
GROUP BY worker_ref_id
HAVING COUNT(worker_ref_id) = 1) AS mySub2