我试图找到排名前2位的频道及其视频以及它们的收入和观看次数总和。 我还想根据渠道的最高收入对结果进行排序
输入
channel_name video views revenue
abc v1 1 4
abc v2 1 5
abc v2 1 5
efg v3 2 3
ijk v4 3 2
预期产量
这是我到目前为止尝试过的,
select Channel_Name, video ,
sum(a.`Revenue`),
sum(views)
rank() over ( partition by `Video` ORDER BY sum(revenue) desc) as ranking
from topchannels
group by Channel_Name, Video
limit 2;
答案 0 :(得分:0)
希望这会有所帮助
SELECT chanel_name
, video
, sum(views) as views
, sum(revenue) as revenue
FROM teste
GROUP
BY chanel_name
, video;
结果:
abc V1 1 4
abc V2 2 10
efg V3 2 3
ijk V4 3 2