日期:2014-05-17  浏览次数:20636 次

sql查询能不能查出具体哪个结果没符合查询条件?
比如我一个sql语句里面好十几个条件,一次性把sql执行完后出来的结果是都符合条件的

但是日志那里又必须为哪些条件没符合做个记录

不知道能不能实现的?总不可能事后在一个个条件去反查,十几个太恐怖了

希望知道的给我个思路谢谢

------解决方案--------------------
探讨
引用:

多少个都是一样的
select * from tb
except
select * from tb where 条件1 and 条件2 and 条件3 and ...


谢谢!except是取差集,但是我的需求是想取哪个条件没符合才造成没筛选出来,我要查出的是条件而不是集合呢

------解决方案--------------------
SQL code

;with cet as(select * from tb 
except
select * from tb where 条件1 and 条件2 and 条件3 and ...)
select case when  条件1 then '' esle '条件1' end +
       case when  条件2 then '' esle '条件2' end +
...  as 缺少的条件 from cet