P, , , .
SELECT COUNT(A.Status), B.Status
FROM AnonymousTable AS A RIGHT OUTER JOIN
(SELECT 'P' AS Status FROM Dual
UNION
SELECT 'U' AS Status FROM Dual
UNION
SELECT 'L' AS Status FROM Dual
UNION
SELECT 'T' AS Status FROM Dual
) AS B ON A.Status = B.Status
GROUP BY B.Status;
4-way UNION - ; . , Dual ( Oracle).
COUNT (A.Status) counts the number of non-zero values in A.Status. RIGHT OUTER JOIN displays a row from B with Status = 'P' and concatenates it with a single NULL for A.Status, which therefore COUNT (A.Status) is considered equal to zero. If you used COUNT (*), you would get 1 to count.
source
share