需要创建一个查找一组记录的查询,如下所示:
ID | Address | Unit | Status
1 |555 Smith Rd | Apt A | Success
2 |555 Smith Rd | Apt B | Success
3 |555 Smith Rd | Apt C | Success
4 |555 Smith Rd | Apt D | Failure
我需要选择Address字段匹配的记录以及状态字段不匹配的位置。理想情况下,我想显示上面例子中的记录组。
答案 0 :(得分:0)
您可以使用分析函数:
select id, address, unit, status
from (select t.*, min(status) over (partition by address) as mins,
max(status) over (partition by address) as maxs
from table t
) t
where mins <> maxs
order by address;