我的数据集名称bollywood.csv:
这是我的数据。 我需要在电影中担任主角最多的演员。 我需要男主角的名字和主演的电影数量。
我的代码是:
select lead, count(*) as nos from bollywood group by lead order by nos desc;
结果是:
Amitabh 3
Akshay 3
John 3
Riteish 2
Shahrukh 2
Sunny 2
Emraan 2
Katrina 2
Nawazuddin 2
Tiger 2
Sharman 2
Manoj 2
Vidya 1
Tusshar 1
Tannishtha 1
Sushant 1
SunnyDeol 1
Sonam 1
Sonakshi 1
Siddarth 1
Shahid 1
Sandeep 1
Salman 1
答案 0 :(得分:0)
按(oracle)的顺序使用rownum伪列。
select from (
select lead, count(*) as nos
from bollywood
group by lead
order by lead desc
)
where rownum = 1
答案 1 :(得分:0)
如果您想让所有演员担任主要角色(可能有多个记录):
select lead, count(*) as nos
from bollywood
group by lead
having count(*) =
(select max(cnt) from
(select lead, count(*) cnt
from bollywood
group by lead ) tblBolly )
答案 2 :(得分:0)
使用窗口功能:
select lead, cnt
from (select lead, count(*) as cnt,
rank() over (order by count(*) desc) as rnk
from bollywood
group by lead
) b
where rnk = 1;