sql-字节跳动2021大数据笔试题-求每个自然周完播率排名前5的用户的网页跳转来源。

–1 建表插入数据
create table if not exists haokan_ads(
user_id int,
user_type int,
day1 DATETIME ,
play_rate double,
resource string);
SELECT * from haokan_ads order by play_rate desc LIMIT 100;
insert into haokan_ads VALUES (1, 1 ,‘2021-01-02 00:00:00’, 0.6,‘ads1’);
insert into haokan_ads VALUES (2 ,1,‘2021-01-08 00:00:00’, 0.9 , ‘ads2’);
insert into haokan_ads VALUES (3 ,0, ‘2021-01-03 00:00:00’ ,0.52, ‘ads3’);
insert into haokan_ads VALUES (4 ,1, ‘2021-01-07 00:00:00’, 0.62 ,‘ads4’);
insert into haokan_ads VALUES (5 ,1 ,‘2021-01-11 00:00:00’,0.19 ,‘ads5’);
insert into haokan_ads VALUES (6 ,0 ,‘2021-01-02 00:00:00’,0.18 ,‘ads6’);
insert into haokan_ads VALUES (7 ,1 ,‘2021-01-02 00:00:00’, 0.49, ‘ads7’);
insert into haokan_ads VALUES (8 ,0, ‘2021-01-03 00:00:00’, 0.39, ‘ads8’);
insert into haokan_ads VALUES (9 ,0 ,‘2021-01-09 00:00:00’, 0.21, ‘ads9’);
insert into haokan_ads VALUES (10 ,0, ‘2021-01-03 00:00:00’, 0.39, ‘ads10’);
insert into haokan_ads VALUES (11 ,0 ,‘2021-01-04 00:00:00’, 0.25, ‘ads11’);
insert into haokan_ads VALUES (12, 0 ,‘2021-01-03 00:00:00’, 0.35, ‘ads12’);
insert into haokan_ads VALUES (13 ,0 ,‘2021-01-09 00:00:00’, 0.1, ‘ads13’);
–2 需求 每个自然周,新用户,完播率排名前5的用户的网页跳转来源?
SELECT
temp_table.week_of_year,
temp_table.user_id,
temp_table.RESOURCE
FROM
(
SELECT
WEEKOFYEAR(day1) week_of_year,
user_id,
RESOURCE
,dense_rank() OVER(PARTITION by WEEKOFYEAR(day1) ORDER BY play_rate DESC) AS orderrank
FROM haokan_ads
WHERE user_type = 1
) temp_table
WHERE orderrank < 6
;
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值