mysql条件查询 确认是哪个筛选条件起作用

需求是这样的,select * from table t where t.a=? and t.b=? and t.c=? and t.d=?

where后面的条件查询的数据量是逐渐变少的的 我想知道如果没有查到数据 是哪个条件起作用了 并获取到这个条件 不想采用逐层判断的方式 能否在一个sql中实现呢

我觉得可以的!你这样去做每个查询返回查询的条数。
select count(*) t3_num ,t3.* from
(
select count(*) t2_num ,t2.* from
(
select count(*) t1_num ,t1.* from

select count(*) t_num ,t.* from table t where t.a=?
)t1 where t1.b=?
) t2 where t2.c=?
) t3 where t.d=?
这样每次查询的数量你就知道了后台得到数据也就可以判断是哪一个条件查询没有数据了!

用or呢,如何????

把and改成or应该是可以的哦,亲

这种是共同起作用的,就如姓名张三,30岁查不出结果,你怎么判断是哪个,是姓名还是年龄导致呢,你单独查30岁有其他人,单独查张三也有这个人或者多个重名的,只是没有30岁的

*
select t1.id,t2.id,t3.id,t4.id,t1.*
from table t1
left join table t2 on t1.id=t2.id on t2.b=?
left join table t3 on t2.id=t3.id on t3.c=?
left join table t4 on t3.id=t4.id on t4.d=?
where t1.a=?
;

你用COALESCE试一试应该可以!

and 是并列条件 or是满足其中一个条件。

可以把你的查询条件都在select后面显示,看看哪些字段跟你的查询条件符合啊,select a.name from a where name=""