Oracle Counting Null,它们都返回相同的结果,但更推荐哪个?还是有更好的方法?
COUNT(DECODE(RESP_CD, NULL, 'X'))
VS
NVL(SUM(DECODE(RESP_CD, NULL, 1, 0)), 0)
答案 0 :(得分:1)
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
);