如何处理NULL值

时间:2016-05-13 10:24:57

标签: sql database oracle

我有以下代码:

`SELECT nt.pl,
         o.cat,
         o.coun,
         COUNT (DISTINCT nt.im) Sub,
         SUM (nt.DOWN + nt.UP) Vol,
         COUNT (*) AS counter,
         CASE
            WHEN nt.tele = '5' THEN 'Vo'
            WHEN nt.tele = ('N/A') AND nt.rat = ('G') THEN 'G'
            ELSE 'Unknown'
         END
            AS Service
    FROM tmp nt, description o
   WHERE nt.pl = o.pl AND nt.time LIKE '201605%'
GROUP BY nt.pl,
         o.cat,
         o.coun,
         nt.tele,
         nt.rat`

问题是列 rat 包含NULL值,结果我收到的行数多于预期。我如何处理这些NULL值。

由于

2 个答案:

答案 0 :(得分:3)

我怀疑,不是在列表中列出nt.telent.rat列,而是需要案例表达式,例如:

  SELECT nt.pl,
         o.cat,
         o.coun,
         COUNT (DISTINCT nt.im) Sub,
         SUM (nt.DOWN + nt.UP) Vol,
         COUNT (*) AS counter,
         CASE
            WHEN nt.tele = '5' THEN 'Vo'
            WHEN nt.tele = ('N/A') AND nt.rat = ('G') THEN 'G'
            ELSE 'Unknown'
         END
            AS Service
    FROM tmp nt, description o
   WHERE nt.pl = o.pl AND nt.time LIKE '201605%'
GROUP BY nt.pl,
         o.cat,
         o.coun,
         CASE
            WHEN nt.tele = '5' THEN 'Vo'
            WHEN nt.tele = ('N/A') AND nt.rat = ('G') THEN 'G'
            ELSE 'Unknown'
         END;

答案 1 :(得分:0)

您正在尝试过滤空值?

 WHERE nt.pl = o.pl AND nt.time LIKE '201605%' AND nt.rat is not null

...