鑒于(有些愚蠢的)資料集:
Name Colour
Mark Red
Mark Yellow
Mark Red
Sarah Blue
Sarah White
我想撰寫一個 SQL 查詢,它將回傳:
Sarah Blue
Sarah White
完全因為顏色重復而忽略了所有“標記”條目。我將如何促進這一點?
uj5u.com熱心網友回復:
首先,我試圖找出具有重復顏色的名稱,然后從我們的資料集中忽略這些名稱。假設你的表名是table1
with temp as
(
Select Name,colour, count(*) from table1 group by Name,colour having count(*)>1
)
Select * from table1 where name not in (select distinct name from temp);
方法二:
Select * from table1 where name not in (select distinct name from (Select Name,colour, count(*) from table1 group by Name,colour having count(*)>1));
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/366513.html
標籤:sql
上一篇:OracleApex解碼復選框將回傳值串列創建為報告的顯示值
下一篇:僅使用SQL輸出特定值
