2014-12-02 127 views
0

屬性需要創建一個發現類似下面的一組記錄的查詢:SQL查詢來查找不匹配二次匹配屬性

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 

,我需要選擇記錄,其中地址字段匹配,並在那裏狀態字段不匹配。理想情況下,我想顯示上述示例中的一組記錄。

+4

相關的用戶名。如果你嘗試過,什麼? – Codeman 2014-12-02 21:45:28

+0

您的查詢現在是什麼樣的?給我們一些工作。 – DLeh 2014-12-02 21:45:35

+0

我的用戶名說了這一切,我真的不知道從哪裏開始,我從來沒有遇到過這種類型的問題。 – NothingWorksandIveTriedNothing 2014-12-02 21:54:14

回答

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;