在下面的示例中获取所需信息时遇到问题。
我的资料:
Id AnotherId Status
-- --------- ------
1 3 new
2 3 old
3 5 new
4 6 new
5 11 old
6 11 old
7 55 new
8 55 new
我正在寻找AnotherId
每个status ='New'实例的区别
所以我的结果看起来像:
5
6
55
这将为我提供大部分帮助,但是我需要所有“新”状态记录:
select AnotherId
from MyData
group by AnotherId
having count(distinct Status) = 1
我似乎无法确切获得所需的东西。任何帮助,将不胜感激!
您可以使用group by
子句:
select AnotherId
from table t
group by AnotherId
having min(status) = max(status) and min(status) = 'new';
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句