1) select *
from employee a
where exists (select 1 from employee b where b.ENO = a.ENO and b.status = 'New')
and exists (select 1 from employee b where b.ENO = a.ENO and b.status = 'Old')
order by 1,2;
ENO SEQUENCE STATUS
---- ---------- -------
A101 1 New
A101 2 Old
A101 3 Old
A101 4 Old
B111 3 Old
B111 5 New
B111 25 New
2) select *
from employee a
where (select count(distinct b.status)
from employee b where b.ENO = a.ENO and b.status in ('New','Old')) = 2
order by 1,2;
ENO SEQUENCE STATUS
---- ---------- -------
A101 1 New
A101 2 Old
A101 3 Old
A101 4 Old
B111 3 Old
B111 5 New
B111 25 New
2条答案
按热度按时间xxe27gdn1#
您可以使用以下查询:
谢谢。
biswetbf2#
这里有一个使用
count() over()
而不使用inner joins
的简单解决方案。ENO|Sequence|状态
-|-|
A101|1|新增
A101|2|旧
A101|3|旧
A101|4|旧
B111|25|新增
B111|5|新增
B111|3|旧
Fiddle