如何在SQL中获得最显示的列值?

时间:2014-04-19 10:22:03

标签: sql ms-access

我有这张桌子:

Aid id date
--------------
 1   1   19/12
 2   1   20/5
 3   2   30/2

我希望获得最能显示的ID,在这种情况下,我希望获得1 (SELECT id)...

应该是这样的:

id
 1

我只想获得最大的计数ID

2 个答案:

答案 0 :(得分:3)

SELECT TOP 1 id from 
(SELECT id, COUNT(id) AS freq FROM table1
GROUP BY id) t1
ORDER BY t1.freq desc

以下是SQLFiddle

答案 1 :(得分:0)

SELECT TOP 1 ArtistID
FROM AwardToArtis
group by ArtistID
order by ArtistID desc

那就解决了我