简体   繁体   English

通过SQL查询计算MS Access中的空白字段

[英]Calculating blank fields in MS Access via a SQL query

I have a table called 'DEMO'. 我有一张名为'DEMO'的桌子。 Under the column 'SEX' I want to find out how many blank cells I have? 在“SEX”栏目下,我想知道我有多少个空白单元格?

I have tried: 我努力了:

SELECT Count(SEX) AS CountIfSexNull FROM DEMO WHERE (((DEMO.SEX) Is Null)); SELECT Count(SEX)AS CountIfSexNull FROM DEMO WHERE(((DEMO.SEX)为空));

however, get a result of 0. 但是,得到0的结果。

When I use 'Query Design' to select the column 'SEX' and manually filter for blanks I get the value of 2. 当我使用“查询设计”选择“SEX”列并手动过滤空白时,我得到值2。

The query works fine on numerical fields, ie AGE and I get a correct answer except instead of 'Is Null' I use '0' ie 查询在数字字段上正常工作,即AGE和我得到正确的答案,除了'Is Null'我使用'0'即

SELECT COUNT(DEMO_AGE) AS CountIfAgeNull FROM DEMO WHERE (DEMO.DEMO_AGE = 0); SELECT COUNT(DEMO_AGE)AS CountIfAgeNull FROM DEMO WHERE(DEMO.DEMO_AGE = 0);

I'm using MS Access 2010 with a .accdb database. 我正在使用带有.accdb数据库的MS Access 2010。

COUNT [Fieldname] does not count nulls, either use an ID or *, for example: COUNT [Fieldname]不计算空值,使用ID或*,例如:

SELECT Count(*) AS CountIfSexNull
FROM DEMO
WHERE DEMO.SEX Is Null

Reference: In SQL is there a difference between count(*) and count(<fieldname>) 参考: 在SQL中,count(*)和count(<fieldname>)之间存在差异

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

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