我有這個表:SQL - 選擇所有穿着兩種不同襯衫顏色的團隊?
播放(日期,時間,地點,名稱,TeamName,ShirtColor)
我想選擇穿正好有兩個不同的襯衫顏色全部隊。
因爲我沒有SQL DB,我想問這兩個(或者可能都不是)哪個是正確的,爲什麼?
SELECT (DISTINCT TeamName)
FROM Playing
WHERE TeamName IN (SELECT TeamName FROM Playing GROUP BY TeamName HAVING COUNT(DISTINCT ShirtColor) = 2)SELECT (DISTINCT TeamName)
FROM Playing
WHERE TeamName IN (SELECT TeamName FROM Playing WHERE COUNT(DISTINCT ShirtColor) = 2 GROUP BY ShirtColor)
@jyparask你是對的,但我沒有完成編輯我的問題。 –
呵呵,沒關係......我剛看到它,我想我應該提到它。 –
第一個OP的查詢是(過度複製但是)是正確的 - 如果括號從第一行中刪除:SELECT DISTINCT TeamName ... –