Counting null and non-null values in a single query

后端 未结 26 1102
星月不相逢
星月不相逢 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条回答
  •  梦毁少年i
    2021-01-29 19:56

    if its mysql, you can try something like this.

    select 
       (select count(*) from TABLENAME WHERE a = 'null') as total_null, 
       (select count(*) from TABLENAME WHERE a != 'null') as total_not_null
    FROM TABLENAME
    

提交回复
热议问题