![](/img/trans.png)
[英]How to group by one column and limit to rows where another column has the same value for all rows in group?
[英]Only return rows if all items with the same ID has all the same value in another column
使用分组依据和子查询
select t.* from
(select subid,status from t t1
group by subid,status
having count(*)>1
) as t1
inner join t on t.subid=t1.subid and t.status=t1.status
您使用not exists
:
select t.*
from table t
where not exists (select 1 from table t1 where t1.subid = t.subid and t1.status = 'Active');
编辑:如果要获取具有相同状态的subid
,则可以执行以下操作:
select t.*
from table t
where not exists (select 1 from table t1 where t1.subid = t.subid and t1.status <> t.status);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.