Counting null and non-null values in a single query

后端 未结 26 1103
星月不相逢
星月不相逢 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 20:04

    usually i use this trick

    select sum(case when a is null then 0 else 1 end) as count_notnull,
           sum(case when a is null then 1 else 0 end) as count_null
    from tab
    group by a
    

提交回复
热议问题