托鲁克玛托,音乐论文,汽车维修人才网
null值影响查询条件的结果,并且结果很微妙。以下是sql中and,or,not的真值表。
表1 and的真值表
true |
false |
null | |
true |
true |
false |
null |
false |
false |
false |
false |
null |
null |
false |
null |
true |
false |
null | |
true |
true |
true |
true |
false |
true |
false |
null |
null |
true |
null |
null |
true |
false |
null |
false |
true |
null |
当两个以上的查询条件与and、or、not组合时,not的优先级最高,其次是and,最后是or。为了避免歧义和确保可移植性最好使用括号。
a between b and c 等价于 (a>=b) and (a<=c),因此根据真值表可以得出between 子句中处理null值的规则。
同样,a in(b,c,d) 等价于 (a=b)or(a=c)or(a=d), 根据真值表,只要这三个表达式中有一个为null,结果返回肯定是null。
因此,between子句和in子句并不增加sql语句的表达能力。
sql 中有null 值测试,即:字段 is (not) null ,但它的返回结果只有两种情况:true或者false。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
数据库SQL---数据库、基本表、视图、索引的定义、修改、删除
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (上)
在 Azure CentOS VM 中配置 SQL Server 2019 AG - (下)
网友评论