I have a table called 'DEMO'. Under the column 'SEX' I want to find out how many blank cells I have?
I have tried:
SELECT Count(SEX) AS CountIfSexNull FROM DEMO WHERE (((DEMO.SEX) Is Null));
however, get a result of 0.
When I use 'Query Design' to select the column 'SEX' and manually filter for blanks I get the value of 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
SELECT COUNT(DEMO_AGE) AS CountIfAgeNull FROM DEMO WHERE (DEMO.DEMO_AGE = 0);
I'm using MS Access 2010 with a .accdb database.
COUNT [Fieldname]
does not count nulls, either use an ID or *, for example:
SELECT Count(*) AS CountIfSexNull
FROM DEMO
WHERE DEMO.SEX Is Null
Reference: In SQL is there a difference between count(*) and count(<fieldname>)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.