Reputation: 33
I have a dataset with null values in but when I run the count() command, the null values are returned as 0:
select year, income_band,
count(income_band)
from income_dataset
where year = "2017"
group by income_band, year
How do I run the count so that the count of the null values are returned?
Thanks!
Upvotes: 0
Views: 31
Reputation: 3293
The function nvl
might fix your issue
Count(nvl(income_band, 1))
Upvotes: 0
Reputation: 5225
WITH DATASET(YEARR,INCOME_BAND)AS
(
SELECT 2017,1 UNION ALL
SELECT 2017,1 UNION ALL
SELECT 2017,2 UNION ALL
SELECT 2017,NULL UNION ALL
SELECT 2017,NULL UNION ALL
SELECT 2017,NULL
)
SELECT T.YEARR,T.INCOME_BAND,
COUNT(CASE WHEN T.INCOME_BAND IS NULL THEN 1 ELSE T.INCOME_BAND END)CNTT
FROM DATASET AS T
GROUP BY T.YEARR,T.INCOME_BAND
Please try conditional aggregation
Upvotes: -1