我有这张桌子:
播放(日期,时间,位置,名称,团队名称,衬衫颜色)
我想选择所有穿着两种不同颜色球衣的球队。
由于我没有 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)