排名

用户解题统计

过去一年提交了

勋章 ①金银铜:在竞赛中获得第一二三名;②好习惯:自然月10天提交;③里程碑:解决1/2/5/10/20/50/100/200题;④每周打卡挑战:完成每周5题,每年1月1日清零。

收藏

收藏日期 题目名称 解决状态
2026-01-11 播放量最高的标签  未解决
2026-01-11 超过3个标签的视频  未解决
2026-01-11 快手面试真题(3)同时在线人数峰值时点  未解决
2026-01-11 快手面试真题(2)同时在线人数峰值  未解决

评论笔记

评论日期 题目名称 评论内容 站长评论
没有评论过的题目。

提交记录

提交日期 题目名称 提交代码
2026-01-11 7月之后再也没活跃过的用户 
with a as 
(select usr_id,date_format(login_time, '%Y-%m') as month ,count(usr_id)as cnt
 from 
user_login_log
 where login_time<='2024-07-31'
group by usr_id,date_format(login_time, '%Y-%m')
having cnt>=10 ) 
,a2 as (
select usr_id
,date_format(login_time, '%Y-%m')as month
,count(usr_id)as cnt
 from 
user_login_log
 where login_time>'2024-07-31'
group by usr_id,date_format(login_time, '%Y-%m')
 having cnt>=10)
selectcount(distinct a.usr_id) as inactive_user_count
from a left join a2
on a.usr_id=a2.usr_id
where a2.usr_id is null
2026-01-11 7月之后再也没活跃过的用户 
with a as 
(select usr_id,month(login_time) month ,count(usr_id)as cnt 
 from 
user_login_log 
 where date(login_time)<='2024-07-31'
group by usr_id,month(login_time)
having cnt>=10 ) 
,a2 as (
select usr_id
,month(login_time) month 
,count(usr_id)as cnt 
 from 
user_login_log 
 where date(login_time)>'2024-07-31'
group by usr_id,month(login_time)
 having cnt>=10)
selectcount(distinct a.usr_id) as inactive_user_count
from a left join a2
on a.usr_id=a2.usr_id
where a2.usr_id is null
2026-01-11 计算每个用户的日均观看时间 
with a as 
(select uid,date(start_time)as date,
 sum(timestampdiff(second,start_time,end_time)) as watch_duration
 from ks_video_wat_log 
group by uid,date(start_time)),
b as (
select uid,round(avg(watch_duration),0) daily_avg_watch_time
from a 
group by uid
)
select * from b
order by daily_avg_watch_time desc
limit 5
2026-01-11 计算每个用户的日均观看时间 
with a as 
(select uid,date(start_time)as date,
 sum(timestampdiff(second,start_time,end_time)) as watch_duration
 from ks_video_wat_log 
group by uid,date(start_time)),
b as (
select uid,round(avg(watch_duration),0) daily_avg_watch_time
from a 
group by uid
)
select * from b
order by daily_avg_watch_time desc
2026-01-11 统计每个作者发布视频的平均互动指数 
with v as 
(select a.video_id,author_id,sum(if_like+case when comment_id IS NOT NULL then 1 else 0 end +if_retweet+if_fav )as hd from ks_video_wat_log a 
 join ks_video_inf b on a.video_id=b.video_id
 group by video_id,author_id),
 a as (select 
 author_id,round(avg(hd),2)as avg_interaction_index
 from v 
 group by author_id
)
select * from a
order by avg_interaction_index desc
2026-01-11 统计每个作者发布视频的平均互动指数 
with v as 
(select a.video_id,author_id,sum(if_like+case when comment_id IS NOT NULL then 1 else 0 end +if_retweet+if_fav )as hd from ks_video_wat_log a 
 join ks_video_inf b on a.video_id=b.video_id
 group by video_id,author_id),
 a as (select 
 author_id,avg(hd)as avg_interaction_index
 from v 
 group by author_id
)
select * from a
order by avg_interaction_index desc
2026-01-11 计算用户观看视频的平均时长 
with a as(select uid 
,video_id
,sum(timestampdiff(SECOND,start_time,end_time)) as duration
from ks_video_wat_log 
group by uid,video_id
 )
select uid,sum(duration)/count(video_id) as avg_watch_duration
 from a 
 group by uid
 order by avg_watch_duration desc
2026-01-11 统计每个作者发布的AI配音视频数量 
select author_id, count(case when if_AI_talking=1 then 1 else null end)ai_video_count
from ks_video_inf 
group by author_id
having ai_video_count>0
order by author_id
;
2026-01-11 快手面试真题(4)按购买金额统计用户数 
with a as
(select rx_month
 ,case WHEN trx_amt BETWEEN 0 AND 100 THEN '0-100'
            WHEN trx_amt BETWEEN 101 AND 1000 THEN '100-1k'
            WHEN trx_amt BETWEEN 1001 AND 10000 THEN '1k-1w'
 else '>1w'
end as amt_range
, usr_id
,trx_amt
from
(select usr_id
 ,date_format(trx_time,'%Y-%m') as rx_month
 ,sum(trx_amt) trx_amt
 from cmb_usr_trx_rcd 
group by usr_id,date_format(trx_time,'%Y-%m') 
)as a
 ),
total as (select 
 rx_month,count(usr_id) as amt
from a 
group by rx_month
 ) ,
c as (select 
 rx_month,amt_range,count(usr_id) as amt
from a 
group by rx_month,amt_range)
select
c.rx_month,c.amt_range,round(c.amt/total.amt*100,2) as percentage
 from c join total on c.rx_month=total.rx_month
 order by c.rx_month,c.amt_range
2026-01-11 分类别的最火直播间 
select live_id,live_nm,live_type,enter_cnt
from (
select *
,row_number()over(partition by live_type order by enter_cnt desc) as rn
from
(select a.live_id,live_nm,live_type
 ,count(distinct usr_id)as enter_cnt
from 
ks_live_t1 a left join ks_live_t2 b 
 on a.live_id=b.live_id
where date_format(enter_time,'%Y-%m-%d %H') = '2021-09-12 23'
group by a.live_id,live_nm,live_type
) as a 
)as b 
where
rn=1
 order by live_id
2026-01-11 不分类别的最火直播间 
select a.live_id,live_nm,count(distinct usr_id) as enter_cnt
from ks_live_t1a
left join ks_live_t2 b on a.live_id=b.live_id
where DATE_FORMAT(a.enter_time, '%Y-%m-%d %H') = '2021-09-12 23'
group by a.live_id,live_nm
 order by enter_cnt desc
 limit 5
2026-01-11 绘制小时进入人数曲线 
select lpad(hour_entered,2,'0') as hour_entered,enter_count
from 
(
select hour(enter_time)hour_entered, count( distinct usr_id) as enter_count
from ks_live_t1 
group by hour(enter_time)) as a
order by hour_entered
2026-01-11 绘制小时进入人数曲线 
select lpad(hour_entered,2,'0') as hour_entered,enter_count
from 
(
select hour(enter_time)hour_entered, count( 1) as enter_count
from ks_live_t1 
group by hour(enter_time)) as a
order by hour_entered
limit 5;
2026-01-11 绘制小时进入人数曲线 
select lpad(hour_entered,2,'0') as hour_entered,enter_count
from 
(
select hour(enter_time)hour_entered, count( distinct usr_id) as enter_count
from ks_live_t1 
group by hour(enter_time)) as a
order by hour_entered
limit 5;
2026-01-11 绘制小时进入人数曲线 
select lpad(hour_entered,2,'0') as hour_entered,enter_count
from 
(
select hour(enter_time)hour_entered, count(distinct usr_id) as enter_count
from ks_live_t1 
group by hour(enter_time)) as a
limit 5;
2026-01-07 绘制小时进入人数曲线 
select lpad(hour_entered, 2, '0') as hour_entered, enter_count
from(
  select 
hour(enter_time) as hour_entered,
  count(1) as enter_count
from ks_live_t1 t1 join ks_live_t2 t2 on t1.live_id = t2.live_id
group by hour(enter_time))
as new_table
order by hour_entered asc
2026-01-07 被收藏次数最多的商品 
select gd_id, 
gd_nm,
count(fav_trq) as fav_count
fromxhs_fav_rcd as a
join 
gd_inf as b 
on a.mch_id=b.gd_id
group by gd_id, gd_nm
order by 
fav_count desc
limit 1;