取满足所有条件的记录 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

    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

最新文章