NOT LIKE 和 LIKE 不返回相反的结果 [英] NOT LIKE and LIKE not returning opposite result
本文介绍了NOT LIKE 和 LIKE 不返回相反的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含 200 条记录的表格,其中 10 条记录的文本包含TAX"一词.
I have a table with 200 records out of which 10 records has text containing the word 'TAX'.
当我正在执行
Select * from tbl1 WHERE [TextCol] LIKE '%TAX%'
然后我得到了包含这 10 条记录的结果集.
then I get the result set with those 10 records correctly .
但是当我试图通过
Select * from tbl1 WHERE [TextCol] NOT LIKE '%TAX%'
它只返回 100 条记录,而不是 190 条.
it's returning 100 records only, instead of 190.
推荐答案
这是否返回正确的结果?
Does this return the correct result ?
Select * from tbl1 WHERE COALESCE([TextCol],'-1') NOT LIKE '%TAX%'
我相信 NULL
值是这里的问题,如果列包含它们,那么 NULL NOT LIKE '%TAX%'
将返回 UNKNOWN/NULL
因此不会被选中.
I believe NULL
values are the issue here, if the column contains them, then NULL NOT LIKE '%TAX%'
will return UNKNOWN/NULL
and therefore won't be selected.
正如@ughai 所建议的,如果性能是一个问题,您也可以使用:
As @ughai suggested, if performance is an issue you can also use:
Select * from tbl1
WHERE [TextCol] NOT LIKE '%TAX%'
OR [TextCol] IS NULL
这篇关于NOT LIKE 和 LIKE 不返回相反的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文