简体   繁体   English

在 sql 中计数不为空

[英]Count not null in sql

I have a table A with column data:我有一个包含列数据的表A

mdr1222
-------
pprgd24
-------
invalid
-------
invalid
abc2345

I want to get a count of the invalid and blank(---).我想获得无效和空白(---)的计数。 I tried :我试过 :

SELECT count(data)
from A
where data = 'invalid' and  null

but it doesn't work.但它不起作用。 Can someone please help me figure out what I am doing wrong here?有人可以帮我弄清楚我在这里做错了什么吗?

This should work as well.这也应该有效。

SUM(CASE WHEN data IS NULL OR data = 'Invalid' THEN 1 ELSE 0 END)
FROM A
select count(column_name) from table_name where column_name is not null

returns number of rows where column_name value is not null返回column_name值不为null的行数

select count(column_name) from table_name where column_name is null

returns number of rows where column_name value is null返回column_name值为null的行数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM