我有2张桌子,EPISODES和PRESENTERS(请参见附图1)。我想找到演出次数最多的节目主持人,并以这样的格式显示:
TIFF NEEDELL 5
我已经找到了使用此查询的最常见的演示者。
select PRESENTERID,count(*) as NumberOfEpisodes from dbo.EPISODES
group by PRESENTERID
having count(*) =(select max(NumberOfEpisodes) from
(select PRESENTERID,count(*) as NumberOfEpisodes from dbo.EPISODES group by PRESENTERID) EPISODES)
答案 0 :(得分:0)
使用Top
并按降序排序计数将起到作用
Select Top 1
PRESENTERID,count(*) as NumberOfEpisodes
From
dbo.EPISODES
Group By PRESENTERID
Order By NumberOfEpisodes DESC