简体   繁体   中英

SQL Count not counting “NULL” in column

I am learning MS SQL & trying to count users entered in record table that are not equal to actionID(column) value 21. Below is the query but it's not giving me result as expected. Its not considering the NULL value. It's showing count as 0, however it's should show result as 1. I have NULL value in actionID column field

Select COUNT(*) from db.record where userID ='xyz' AND NOT actionID = 21

This is for MySQL You need a NULL -safe comparison:

NOT actionID <=> 21

Almost all comparisons to NULL return NULL . And NOT NULL is still NULL

For MS SQL use it like below

 (actionID <> 21 OR actionID is null)

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.

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