我有一张桌子
create table us
(
a number
);
现在我有如下数据:
a
1
2
3
4
null
null
null
8
9
现在我需要一个查询来计算列a中的空值和非空值
我有一张桌子
create table us
(
a number
);
现在我有如下数据:
a
1
2
3
4
null
null
null
8
9
现在我需要一个查询来计算列a中的空值和非空值
当前回答
以防你想把它记录在一条记录里:
select
(select count(*) from tbl where colName is null) Nulls,
(select count(*) from tbl where colName is not null) NonNulls
;-)
其他回答
Try
SELECT
SUM(ISNULL(a)) AS all_null,
SUM(!ISNULL(a)) AS all_not_null
FROM us;
简单!
使用ISNULL嵌入函数。
我在postgres 10中创建了这个表,下面两种方法都有效:
从我们中选择count(*)
and
从我们中选择count(a为空)
a为空的元素个数:
select count(a) from us where a is null;
a不为空的元素个数:
select count(a) from us where a is not null;
正如我理解你的查询,你只需要运行这个脚本并获得Total Null,Total NotNull行,
select count(*) - count(a) as 'Null', count(a) as 'Not Null' from us;