oracle计算null值,哪个更合适?

时间:2013-11-19 04:58:01

标签: sql oracle

Oracle Counting Null,它们都返回相同的结果,但更推荐哪个?还是有更好的方法?

COUNT(DECODE(RESP_CD, NULL, 'X'))

VS

NVL(SUM(DECODE(RESP_CD, NULL, 1, 0)), 0)

1 个答案:

答案 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
     );