我有以下代码:
`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值。
由于
答案 0 :(得分:3)
我怀疑,不是在列表中列出nt.tele
和nt.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
...