Counting null and non-null values in a single query

后端 未结 26 1104
星月不相逢
星月不相逢 2021-01-29 19:31

I have a table

create table us
(
 a number
);

Now I have data like:

a
1
2
3
4
null
null
null
8
9

Now I need

26条回答
  •  清歌不尽
    2021-01-29 19:41

    Try this..

    SELECT CASE 
             WHEN a IS NULL THEN 'Null' 
             ELSE 'Not Null' 
           END a, 
           Count(1) 
    FROM   us 
    GROUP  BY CASE 
                WHEN a IS NULL THEN 'Null' 
                ELSE 'Not Null' 
              END 
    

提交回复
热议问题