所以我有一张桌子(人),其中包含人名,年龄,眼睛颜色,喜欢的电影等栏目。
如何使用SQL(Microsft Access)找到最流行的眼睛颜色,只返回眼睛颜色(不是计数),而不使用top,因为可能有多个具有相同计数的颜色。
谢谢
答案 0 :(得分:1)
SELECT
EyeColor
FROM
Person
GROUP BY
EyeColor
HAVING
COUNT(*) = (
SELECT MAX(i.EyeColorCount) FROM (
SELECT COUNT(*) AS EyeColorCount FROM Person GROUP BY EyeColor
) AS i
)
答案 1 :(得分:0)
在Access中,我认为你需要的是:
SELECT First(t.Eyecolor) AS FirstOfEyeColor
FROM (SELECT p.EyeColor, Count(p.EyeColor) AS C
FROM Person p
GROUP BY p.EyeColor
ORDER BY Count(p.EyeColor) DESC) AS t;