Reputation: 922
Oracle Counting Null, both of them are returning same result, but which is more recommended? or is there better way?
COUNT(DECODE(RESP_CD, NULL, 'X'))
vs
NVL(SUM(DECODE(RESP_CD, NULL, 1, 0)), 0)
Upvotes: 0
Views: 66
Reputation: 2602
SELECT SUM(n_count), SUM(x_count)
FROM
(SELECT CASE WHEN resp_cd IS NULL THEN 1 END n_count,
CASE WHEN resp_cd = 'x' THEN 1 END x_count
FROM your_table
);
Upvotes: 1