Counting null and non-null values in a single query

后端 未结 26 1617
星月不相逢
星月不相逢 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:44

    If you're using MS Sql Server...

    SELECT COUNT(0) AS 'Null_ColumnA_Records',
    (
        SELECT COUNT(0)
        FROM your_table
        WHERE ColumnA IS NOT NULL
    ) AS 'NOT_Null_ColumnA_Records'
    FROM your_table
    WHERE ColumnA IS NULL;
    

    I don't recomend you doing this... but here you have it (in the same table as result)

提交回复
热议问题