简体   繁体   English

SQL选择where子句操作<>

[英]Sql select where clause operation <>

i want to get column value that has some other value and null but don't want value that equal to some point. 我想获取具有其他值和null的列值,但不希望该值等于某个点。

Example

ID|VID  |IC  |
1 |v001 |123 |
2 |v001 |null|
3 |v003 |456 |
4 |v004 |null|

so i want to get ID which IC is not equal to 123. but i only get ID 3 but ID 2 and 4 will not shown out in sql. 所以我想获得ID,它的IC不等于123。但是我只获得ID 3,但是ID 2和4在sql中不会显示出来。 i have tried select * from table where IC<>'123' and IC is null but it shows nothing. 我试过select * from table where IC<>'123' and IC is null但它什么也没显示。

SELECT * FROM table WHERE IC != '123' OR IC IS NULL

You want OR , not AND : 您想要OR ,而不是AND

select * from table where IC != 123 OR IC IS NULL

Any comparison with NULL produces the third logic value , UNKNOWN , and any negation of UNKNOWN produces UNKNOWN , so you have to treat the NULL s separately - but, of course, for any particular row, it cannot possibly be true that it's simultaneously got a value different from 123 but at the same time it's NULL . 任何与NULL比较都将产生第三个逻辑值 UNKNOWN ,而对UNKNOWN任何否定都将产生UNKNOWN ,因此您必须分别处理NULL ,但是对于任何特定的行,当然不可能同时获得一个值不同于123但同时为NULL So AND is wrong. 所以AND是错误的。

Try the following: 请尝试以下操作:

SELECT *  
FROM table   
WHERE IC != '123'   
OR IC IS NULL  

尝试这个 :

select * from table where ISNULL(IC,0)<>'123'    

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

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