table_a表是用户表,table_b是条件表,每个用户对应多个条件,并且用户对应条件的状态有可能是true或者false,现在需要找出在table_b中所有条件都是true的用户。
table_a表的数据
table_b表的数据
通过分析a表和b表的数据可以得出,只有用户“王二”满足所有条件,期望的结果就是
实现sql语句
select a.* from( select [aid],sum(case when [state]='true' then 0 else 1 end) as total from [table_b] group by [aid]) b inner join [table_a] a on b.aid=a.id where total =0
