排名

用户解题统计

过去一年提交了

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

收藏

收藏日期 题目名称 解决状态
2026-03-19 横屏与竖屏视频的完播率(按AI配音和字幕分类)  已解决
2026-02-07 播放量最高的标签  已解决
2026-02-04 会员与非会员的日均观看视频数量  已解决
2026-02-04 抖音面试真题(4)T+1月留存  已解决
2026-01-08 一线城市历年平均气温  已解决
2026-01-08 上月活跃用户数  已解决

评论笔记

评论日期 题目名称 评论内容 站长评论
2026-01-30 小丑竟是我自己 
题目写的是小丑指数在88和99之间,但是正确答案是小丑指数在80和99之间,题目写错了
啥也没说
2026-01-29 窗口函数(1)年度前三和每月前三,搞懂排序窗口函数 
-- rollup方法(mysql8.0+)
with t1 as (
select date_format(trx_time,'%Y-%m') as trx_mon,mch_nm,sum(trx_amt) as sum_trx_amt
from cmb_usr_trx_rcd
where trx_time>='2024-01-01' and trx_time<'2025-01-01' and usr_id=5201314520
group by mch_nm,trx_mon 
with rollup 
having trx_mon is not null or mch_nm is not null
),
t2 as (
select coalesce(trx_mon,2024) as trx_mon,mch_nm,sum_trx_amt,row_number() over(partition by coalesce(trx_mon,2024) order by sum_trx_amt desc) as rk 
from t1
)
select trx_mon,mch_nm,sum_trx_amt 
from t2 
where rk<=3 
order by trx_mon asc,sum_trx_amt desc
啥也没说
2026-01-29 深圳气温异常年份 
mysql> select round(cast(23.12500000 as float),2) as 单精度浮点数;
+--------------------+
| 单精度浮点数       |
+--------------------+
|              23.12 |
+--------------------+
1 row in set (0.00 sec)

mysql> select round(cast(23.12500000 as double),2) as 双精度浮点数;
+--------------------+
| 双精度浮点数       |
+--------------------+
|              23.12 |
+--------------------+
1 row in set (0.00 sec)
mysql> select round(23.12500000,2) as mysql正常小数;
+-------------------+
| mysql正常小数     |
+-------------------+
|             23.13 |
+-------------------+
1 row in set (0.00 sec)
啥也没说

提交记录

提交日期 题目名称 提交代码
2026-03-20 快手面试真题(4)按购买金额统计用户数 
with t1 as (
select usr_id,date_format(trx_time,'%Y-%m') as rx_month,
sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd 
group by usr_id,rx_month
order by rx_month asc
)
select rx_month,
case when trx_amt<=100 then '0-100'
when trx_amt>100 and trx_amt<=1000 then '100-1k'
when trx_amt>1000 and trx_amt<=10000 then '1k-1w'
else '>1w'
end as amt_range,
round(100*count(*)/sum(count(*)) over (partition by rx_month),2) as percentage
from t1 
group by rx_month,amt_range 
order by rx_month asc,amt_range asc
2026-03-19 横屏与竖屏视频的完播率(按AI配音和字幕分类) 
select screen_type,
round(100*sum(if_AI_talking=1 and if_hint=1 and timestampdiff(second,start_time,end_time)>=duration)/sum(if_AI_talking=1 and if_hint=1),2) as AI_with_hint,
round(100*sum(if_AI_talking=1 and if_hint=0 and timestampdiff(second,start_time,end_time)>=duration)/sum(if_AI_talking=1 and if_hint=0),2) as AI_no_hint,
round(100*sum(if_AI_talking=0 and if_hint=1 and timestampdiff(second,start_time,end_time)>=duration)/sum(if_AI_talking=0 and if_hint=1),2) as no_AI_with_hint,
round(100*sum(if_AI_talking=0 and if_hint=0 and timestampdiff(second,start_time,end_time)>=duration)/sum(if_AI_talking=0 and if_hint=0),2) as no_AI_no_hint
from ks_video_inf k1 join ks_video_wat_log k2 using (video_id)
group by screen_type
2026-03-19 专注力强的总用户数 
with t1 as (
select uid
from ks_video_inf k1 join ks_video_wat_log k2 using (video_id)
where duration>180 and start_time>=date_sub(curdate(),interval 1 month)
group by uid 
having count(distinct case when timestampdiff(second,start_time,end_time)>=duration then video_id end)>=2
)
select count(*) as total_users 
from t1
2026-03-19 总播放时长最长的视频 
select video_id,title,
round(sum(timestampdiff(second,start_time,end_time))/3600,2) as total_play_duration_hours
from ks_video_inf k1 join ks_video_wat_log k2 using (video_id)
where start_time>=date_sub(curdate(),interval 1 month)
group by video_id,title
order by total_play_duration_hours desc 
limit 5
2026-03-18 近1个月最热短视频 
select video_id,title,
count(*) as view_count,
sum(if_like) as like_count,
sum(if_retweet) as retweet_count,
sum(if_fav) as fav_count,
sum(if_like)+sum(if_fav)+sum(if_retweet) as total_interactions
from ks_video_inf k1 join ks_video_wat_log k2 using (video_id)
where start_time>=date_sub(curdate(),interval 1 month)
group by video_id,title 
order by total_interactions desc 
limit 3
2026-03-18 绘制小时进入人数曲线 
select case when hour(enter_time)>=10 then hour(enter_time)
else concat('0',hour(enter_time)) 
end as hour_entered,
count(distinct usr_id) as enter_count
from ks_live_t1 
group by hour_entered
2026-03-18 基于共同兴趣爱好的餐厅推荐(6)-好基友(5) 
with t1 as (
select cust_uid,mch_nm
from mt_trx_rcd1
where cust_uid='MT10000'
group by cust_uid,mch_nm
),
t2 as (
select cust_uid,mch_nm
from mt_trx_rcd1
where cust_uid<>'MT10000'
group by cust_uid,mch_nm
)
select t1.cust_uid,t2.cust_uid as cust_uid_1
from t1 join t2 using (mch_nm)
group by t1.cust_uid,t2.cust_uid
having count(*)=(select count(distinct mch_nm) from mt_trx_rcd1 where cust_uid='MT10000')
order by cust_uid_1 asc
2026-03-18 基于共同兴趣爱好的餐厅推荐(6)-好基友(5) 
with t1 as (
select cust_uid,mch_nm
from mt_trx_rcd1
where cust_uid='MT10000'
group by cust_uid,mch_nm
),
t2 as (
select cust_uid,mch_nm
from mt_trx_rcd1
where cust_uid<>'MT10000'
group by cust_uid,mch_nm
)
select t1.cust_uid,t2.cust_uid as cust_uid_1
from t1 join t2 using (mch_nm)
group by t1.cust_uid,t2.cust_uid
having count(*)=14
order by cust_uid_1 asc
2026-03-18 基于共同兴趣爱好的餐厅推荐(4)-好基友(2) 
select 'MT10000' as cust_uid,cust_uid as cust_uid1
from mt_trx_rcd1 
where cust_uid<>'MT10000'
group by cust_uid1
having sum(mch_nm='庄家界(千灯店)')>=1 and sum(mch_nm='黄记烘培宫廷桃酥王')>=1 
order by cust_uid1 asc
2026-03-18 基于共同兴趣爱好的餐厅推荐(3)-好基友(1) 
with t1 as (
select cust_uid
from mt_trx_rcd1
where mch_nm='兰州李晓明拉面馆' and cust_uid<>'MT10000'
group by cust_uid
)
select 'MT10000' as cust_uid,cust_uid as cust_uid1,'兰州李晓明拉面馆' as mch_nm
from t1 
order by cust_uid1 asc
2026-03-17 高价值客户及其最常访问的商户类型 
with t1 as (
select cust_uid,
datediff(curdate(),max(trx_dt)) as recency,
count(distinct trx_dt) as frequency,
avg(trx_amt) as monetary
from mt_trx_rcd_f 
group by cust_uid
),
t2 as (
select cust_uid,
ntile(3) over (order by recency desc) as recency_score,
ntile(3) over (order by frequency asc) as frequency_score,
ntile(3) over (order by monetary asc) as monetary_score
from t1
) 
select mch_typ2,count(*) as visit_count 
from t2 join mt_trx_rcd_f m using (cust_uid)
where recency_score+frequency_score+monetary_score>=7
group by mch_typ2
order by visit_count desc
2026-03-17 找出流失风险客户(R=1且F<=2) 
with t1 as (
select cust_uid,
datediff(curdate(),max(trx_dt)) as recency,
count(distinct trx_dt) as frequency,
avg(trx_amt) as monetary
from mt_trx_rcd_f 
group by cust_uid
),
t2 as (
select cust_uid,
ntile(3) over (order by recency desc) as recency_score,
ntile(3) over (order by frequency asc) as frequency_score,
ntile(3) over (order by monetary asc) as monetary_score
from t1
)
select cust_uid,recency_score,frequency_score,monetary_score 
from t2 
where recency_score=1 and frequency_score<=2
order by cust_uid asc
2026-03-17 基于购买次数和累计购买金额计算每个用户的RFM评分 
select cust_uid,
case when datediff(curdate(),max(trx_dt))>30 then 1 
when datediff(curdate(),max(trx_dt))<10 then 3
else 2 
end as recency_score,
case when count(*)<=5 then 1 
when count(*)>15 then 3
else 2 
end as frequency_score,
case when sum(trx_amt)<2000 then 1
when sum(trx_amt)>5000 then 3 
else 2 
end as monetary_score
from mt_trx_rcd_f 
group by cust_uid
order by cust_uid asc
2026-03-16 基于消费天数和平均单笔购买金额计算每个用户的RFM评分 
select cust_uid,
case when datediff(curdate(),max(trx_dt))>30 then 1
when datediff(curdate(),max(trx_dt))<10 then 3 
else 2 
end as recency,
case when count(distinct trx_dt)<=10 then 1
when count(distinct trx_dt)>20 then 3 
else 2 
end as frequency,
case when avg(trx_amt)<150 then 1 
when avg(trx_amt)>250 then 3 
else 2 
end as monetary
from mt_trx_rcd_f 
group by cust_uid 
order by cust_uid asc
2026-03-16 计算每个用户的RFM值(1) 
select cust_uid,
datediff(curdate(),max(trx_dt)) as recency,
count(*) as frequency,
sum(trx_amt) as monetary
from mt_trx_rcd_f 
group by cust_uid
order by cust_uid asc
2026-03-16 直观对比两种频率计算的差异(F) 
select cust_uid,
count(*) as transaction_count,
rank() over (order by count(*) desc) as transaction_rank,
count(distinct trx_dt) as active_days_count,
rank() over (order by count(distinct trx_dt)) as active_days_rank,
abs(cast(rank() over (order by count(*) desc) as signed)-cast(rank() over (order by count(distinct trx_dt) desc) as signed)) as rank_difference
from mt_trx_rcd_f 
group by cust_uid
order by rank_difference desc
2026-03-16 直观对比两种频率计算的差异(F) 
select cust_uid,
count(*) as transaction_count,
rank() over (order by count(*) desc) as transaction_rank,
count(distinct trx_dt) as active_days_count,
rank() over (order by count(distinct trx_dt)) as active_days_rank,
abs(cast(rank() over (order by count(*) desc) as signed)-cast(rank() over (order by count(distinct trx_dt) desc) as signed)) as rank_difference
from mt_trx_rcd_f 
group by cust_uid
order by rank_difference desc,cust_uid asc
2026-03-16 直观对比两种频率计算的差异(F) 
select cust_uid,
count(*) as transaction_count,
rank() over (order by count(*) desc) as transaction_rank,
count(distinct trx_dt) as active_days_count,
rank() over (order by count(distinct trx_dt)) as active_days_rank,
abs(cast(rank() over (order by count(*) desc) as signed)-cast(rank() over (order by count(distinct trx_dt)) as signed)) as rank_difference
from mt_trx_rcd_f 
group by cust_uid
order by rank_difference desc,cust_uid asc
2026-03-16 面包甜点店的市场份额 
select mch_nm,
sum(trx_amt) as restaurant_revenue,
sum(sum(trx_amt)) over () as category_revenue,
round(100*sum(trx_amt)/sum(sum(trx_amt)) over (),2) as market_share
from mt_trx_rcd1 
where trx_dt between '2021-03-01' and '2021-03-31' and mch_typ2='面包甜点'
group by mch_nm
2026-03-16 每月新增用户占比 
with t1 as (
select mch_nm,min(trx_dt) as trx_dt,cust_uid
from mt_trx_rcd1
group by mch_nm,cust_uid
)
select m.mch_nm,date_format(m.trx_dt,'%Y-%m') as month,
count(distinct m.cust_uid) as total_users,
count(distinct t1.cust_uid) as new_users,
round(100*count(distinct t1.cust_uid)/count(distinct m.cust_uid),2) as new_user_ratio
from mt_trx_rcd1 m left join t1 using (mch_nm,trx_dt,cust_uid)
group by m.mch_nm,month
having count(distinct t1.cust_uid)>0