1.not in
生产上遇到一个问题,发现原来有个sql:select * from A 查出来是七条数据,但是在加了select * from A where type not in(‘4’,‘5’)后查询结果变成三条,而当前表中没有type n为‘4’或‘5’的数据,少的四条type为null。
查询发现:使用not in的时候,只会查询从指定列不为空的列中过滤,会过滤掉指定列为null的数据
解决办法:not exists替换not in不会影响null值数据
有些not exists仍不能展示null的,可以加or 的方式来解决,如select * from A where type not in(‘4’,‘5’) or type is null
sql相关的问题
最新推荐文章于 2022-03-22 22:13:31 发布