排名

用户解题统计

过去一年提交了

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

错题集 数据思维刷题中答错的题目

模块 知识点 题目 你的答案 正确答案 操作
暂无错题,继续保持!

收藏

收藏日期 题目名称 解决状态
2026-03-27 计算每个用户的受欢迎程度  已解决
2025-04-21 客群分布直方图  已解决
2025-04-21 统计每一类RFM用户的数量  已解决
2025-04-21 4分及以下客户去的最后一家餐厅  已解决
2025-04-21 9分客户最爱去的Top3餐厅  已解决
2025-04-19 直观对比两种频率计算的差异(F)  已解决
2025-04-15 得物面试真题(4)首单Mac二单iPhone的客户  已解决
2025-04-15 得物面试真题(1)每周iPhone用户和非iPhone用户  已解决
2025-04-15 各商品漏斗转化率  已解决
2025-04-15 从商品角度统计收藏到购买的转化率  已解决
2025-04-14 好友步数排名-考虑反向好友关系  已解决
2025-04-14 好友步数排名-不考虑反向好友关系  已解决
2025-04-13 会员与非会员的日均观看视频数量  已解决
2025-04-13 每个视频类型的T+3留存率  已解决
2025-04-13 钢铁直男的观看记录  已解决
2025-04-13 只观看放映厅的用户  已解决
2025-04-13 每天新增用户的会员转化比例  已解决
2025-04-13 每天新增会员  已解决
2025-04-13 哔哩哔哩面试真题(6)全年会员收入分类  已解决
2025-04-13 哔哩哔哩面试真题(4)每周分摊会员收入  已解决
2025-04-13 哔哩哔哩面试真题(2)计算春节周会员收入  已解决
2025-04-13 频道重合指数  已解决
2025-04-13 多类别观看指数计算  已解决
2025-04-12 绘制小时进入人数曲线  已解决
2025-04-12 快手面试真题(3)同时在线人数峰值时点  已解决
2025-04-11 快手面试真题(2)同时在线人数峰值  已解决
2025-04-10 播放量最高的标签  未解决
2025-04-10 计算完播率(按人数)  已解决
2025-04-09 夜深与专车比例的相关系数  已解决
2025-04-09 晚时段专车比例  已解决
2025-04-09 滴滴面试真题(4)未完成订单在第二天继续呼叫的比例  已解决
2025-04-09 滴滴面试真题(2)打车订单呼叫应答时间  已解决
2025-04-09 滴滴面试真题(1)-打车订单应答率  已解决
2025-04-09 连续登录3天及以上  已解决
2025-04-09 上月活跃用户数  已解决
2025-04-09 7月之后再也没活跃过的用户  已解决
2025-04-09 10月1日后再也没活跃过的用户  已解决
2025-04-08 抖音面试真题(4)T+1月留存  已解决
2025-04-08 抖音面试真题(5)新用户的T+1月留存  已解决
2025-04-08 抖音面试真题(3)一次性计算T+3、T+7、T+14留存率(2)  已解决
2025-04-08 抖音面试真题(2)一次性计算T+1、T+3、T+7、T+14留存率  已解决
2025-04-07 抖音面试真题(1)T+1日留存率  已解决
2025-04-07 统计每个城市各状态的单量  已解决
2025-04-07 计算每个城市的有效订单完成率  已解决
2025-03-10 基于共同兴趣爱好的餐厅推荐(6)-好基友(5)  已解决
2025-03-10 多云天气天数  已解决
2025-01-26 小丑竟是我自己  未解决
2025-01-25 海王:1小时发3个红包  已解决
2025-01-20 德州扑克起手牌-同花两高张  未解决
2025-01-20 通勤、午休、临睡个时间段活跃人数分布  已解决

评论笔记

评论日期 题目名称 评论内容 站长评论
2025-02-03 餐厅的客单价增长趋势 
//自己记录用
**考察coalesce用法,计算同环比场景,被做对比的数据为0时,取0
**考察nullif用法,计算比例,同环比,上期或同期为0, 做分母,避免被除数为0,nullif判断被除数是否为0,为0则取null
**考察round用法,计算同环比,保留小数,比值先乘以100,再四舍五入保留小数部位
**考察开窗函数
啥也没说
2025-01-26 小丑竟是我自己 
比例是 (1-A/B)*100 吗
是的~,你再试下应该能通过了
2025-01-26 小丑竟是我自己 
知识点:
rcv_datetime != '1900-01-01 00:00:00'  1900-01-01代表没有列值的记录,此处用作判断没有被接收的红包的记录
啥也没说
2025-01-21 德州扑克起手牌-同花两高张 
select count(1) as cnt,
			(select count(1) from hand_permutations) as ttl_cnt,
            round(count(1)/(select count(1) from hand_permutations),4) as p
from 
(select distinct card1,card2
from hand_permutations 
where right(card1,1)=right(card2,1)
and (left(card1,length(card1)-1) between 'A' and 'K') 
and (left(card2,length(card2)-1) between 'A' and 'K')) t1
啥也没说
2025-01-21 文科潜力股 
SELECT *
 FROM scores 
 where ((subject ='历史' and score>90)
 or (subject ='地理' and score>90)
 or (subject ='政治' and score>90))
 and exam_date='2024-06-30'
 order by score desc,student_id,subject
啥也没说
2025-01-21 找出所有以酒店为起点或终点的类别组合的最热门路线 
注意关联条件的列名,以及题解是求最热门的路线组合,需要再次分区(分组)排名
啥也没说
2025-01-21 至少两门科目大于等于110分的学生 
select *
 from subject_score
 where (chinese>=110 and math>=110)
 or (chinese>=110 and english>=110)
 or (math>=110 and english>=110)
 order by student_id

select a1.*
from subject_score a1
inner join 
(select student_id,
			(c1+m1+e1) as tll
from
 (select student_id,
 			case when chinese>=110 then 1 else 0 end as c1,
            case when math>=110 then 1 else 0 end as m1,
            case when english>=110 then 1 else 0 end as e1
 from subject_score) t 
) a2 
on a1.student_id=a2.student_id
where a2.tll>=2


select *
from subject_score
where if(chinese>=110,1,0)+if(math>=110,1,0)+if(english>=110,1,0) >=2
啥也没说
2025-01-21 渣男腰子可真行,端午中秋干不停 
多个where筛选条件,注意and和or的运算优先级,括号的使用
啥也没说
2025-01-21 分组与聚合函数(5)五花八门的项目,其实都有固定套路(2) 
计算客单数和消费人数,人均客单数的区别
啥也没说
2025-01-21 条件过滤(3)Hour函数很给力,组合条件要仔细 
注意输出排序
现在不用注意了😄
2025-01-21 通勤、午休、临睡个时间段活跃人数分布 
使用变量?
跟变量木有关系,本网站所有题都不需要使用变量。
2025-01-21 通勤、午休、临睡个时间段活跃人数分布 
select 
(select count(distinct usr_id)
from user_login_log
where 
 ((substr(login_time,12,8) between '07:30:00' and '09:30:00')
or (substr(login_time,12,8) between '18:30:00' and '20:30:00'))
and (substr(login_time,1,10) between date_add(current_date()-day(current_date())+1,interval -1 month) and date_add(last_day(current_date()),interval -1 month))) as commute,
(select count(distinct usr_id)
from user_login_log
where (substr(login_time,12,8) between '11:30:00' and '14:00:00')
and (substr(login_time,1,10) between date_add(current_date()-day(current_date())+1,interval -1 month) and date_add(last_day(current_date()),interval -1 month))) as lunch_break,
(select count(distinct usr_id)
from user_login_log
where (substr(login_time,12,8) between '22:30:00' and '01:00:00')
and (substr(login_time,1,10) between date_add(current_date()-day(current_date())+1,interval -1 month) and date_add(last_day(current_date()),interval -1 month))) as bedtime
啥也没说
2025-01-21 性别已知的听歌用户 
在听歌记录表取值,关联用户信息表
啥也没说
2025-01-20 各地区包含“中国”或“中”字开头的公司数量及比例 
和上题例不同,公司名称条件不用去除以“中国”结尾的,且包含“中”字的公司不需要限定以中字开头。
注意order by之后不接聚合函数,order by和聚合函数有不同的语义和执行顺序。

输出结果proportiton的小数位为4位,结果未通过。
啥也没说
2025-01-20 每个行业最早上市的公司 
只考虑那些名称以“中国”开头或包含“中”字的公司:
1. 以“中国”开头的公司,需要同时剔除以“中国”结尾的公司
2. 包含“中”字的公司,题解为以“中”字开头的公司,不是名称出现“中”字的公司
这里有一些误解
啥也没说
2025-01-19 条件过滤(1)异地男友有异常,数分闺蜜来帮忙 
使用date_format函数可以吗
可以的。实际业务中,如果用于过滤,怎么方便怎么来;如果是用于输出,要严格遵守输出要求,因为后续就要导入到pythonexcel啥的,会有格式要求,那就推荐date_format。😁

提交记录

提交日期 题目名称 提交代码
2026-05-12 QQ音乐(三)歌手平均播放量 
select singer_name
		,count(distinct s.song_id) as song_cnt
,count(l.song_id) as total_listen
,round(count(l.song_id)/count(distinct s.song_id),2) as avg_listen
from singer_info si 
inner join song_info s on si.singer_id=s.origin_singer_id
inner join listen_rcd l on s.song_id=l.song_id
group by singer_name 
order by 4 desc
2026-05-12 QQ音乐(三)歌手平均播放量 
select singer_name
		,count(distinct l.song_id) as song_cnt
,count(l.song_id) as total_listen
,round(count(l.song_id)/count(distinct l.song_id),2) as avg_listen
from singer_info si 
inner join song_info s on si.singer_id=s.origin_singer_id
inner join listen_rcd l on s.song_id=l.song_id
group by singer_name 
order by 4 desc
2026-04-25 基于消费天数和平均消费金额NTILE分组计算每个用户的RFM评分 
with basedata as
(
select cust_uid as user_id
		,datediff(curdate(),max(trx_dt)) as recency
,count(distinct trx_dt) as frequency
,sum(trx_amt)/count(*) as monetary
from mt_trx_rcd_f
group by 1
order by 1)
select user_id
		,ntile(3) over(order by recency desc) as recency_score
,ntile(3) over(order by frequency) as frequency_score
,ntile(3) over(order by monetary) as monetary_score
from basedata
order by 1
2026-04-25 基于消费天数和平均消费金额NTILE分组计算每个用户的RFM评分 
with basedata as
(
select cust_uid as user_id
		,datediff(curdate(),max(trx_dt)) as recency
,count(distinct trx_dt) as frequency
,sum(trx_amt)/count(*) as monetary
from mt_trx_rcd_f
group by 1
order by 1)
select user_id
		,ntile(3) over(order by recency desc) as recency_score
,ntile(3) over(order by frequency ) as frequency_score
,ntile(3) over(order by monetary) as monetary_score
from basedata
order by 1
2026-04-25 基于购买次数和累计购买金额计算每个用户的RFM评分 
with basedata as
(
select cust_uid as user_id
		,datediff(curdate(),max(trx_dt)) as recency
,count(*) as frequency
,sum(trx_amt) as monetary
from mt_trx_rcd_f
group by 1
order by 1)
select user_id
		,case when recency <10 then 3 when recency <=30 then 2 else 1 end as recency_score
,case when frequency between 1 and 5 then 1 when frequency between 6 and 15 then 2 when frequency >15 then 3 else 'unknown' end as frequency_score
,case when monetary<2000 then 1 when monetary <=5000 then 2 else 3 end as monetary_score
from basedata
order by 1
2026-04-25 基于购买次数和累计购买金额计算每个用户的RFM评分 
with basedata as
(
select cust_uid as user_id
		,datediff(curdate(),max(trx_dt)) as recency
,count(*) as frequency
,sum(trx_amt) as monetary
from mt_trx_rcd_f
group by 1
order by 1)
select user_id
		,case when recency<10 then 3 when recency<=30 then 2 else 1 end as recency_score
,case when frequency>15 then 3 when frequency between 6 and 15 then 2 when frequency between 1 and 5 then 1 else 'unknown' end as frequency_score
,case when monetary <2000 then 1 when monetary <=5000 then 2 else 3 end as monetary_score
from basedata
order by 1
2026-04-25 基于购买次数和累计购买金额计算每个用户的RFM评分 
with basedata as
(
select cust_uid as user_id,
		datediff(curdate(),max(trx_dt)) as recency,
count(*) as frequency,
sum(trx_amt) as monetary
from mt_trx_rcd_f
group by 1
order by 1)
select user_id,
		case when recency >30 then 1 when recency between 10 and 30 then 2 else 3 end as recency_score,
case when frequency between 1 and 5 then 1 when frequency between 6 and 15 then 2 
when frequency >15 then 3 else '其他' end as frequency_score,
case when monetary <2000 then 1 when monetary between 2000 and 5000 then 2 else 3 end as monetary_score
from basedata
order by 1
2026-04-24 基于消费天数和平均单笔购买金额计算每个用户的RFM评分 
with basedata as 
(
select cust_uid as user_id,
datediff(curdate(),max(trx_dt)) as recency,
count(distinct trx_dt) as frequency,
sum(trx_amt)/count(*) as monetary
from mt_trx_rcd_f
group by 1
order by 1)
select user_id,
case when recency <10 then 3
		when recency between 10 and 30 then 2
else 1 end as recency_score,
case when frequency between 1 and 10 then 1
 when frequency between 11 and 20 then 2
 when frequency >20 then 3 end as frequency_score,
case when monetary <150 then 1
			when monetary between 150 and 250 then 2
when monetary >250 then 3 end as monetary_score
from basedata
order by 1
2026-04-24 计算每个用户的RFM值(2) 
select cust_uid as user_id,
datediff(curdate(),max(trx_dt)) as recency,
count(distinct trx_dt) as frequency,
round(sum(trx_amt)/count(*),4) as monetary
from mt_trx_rcd_f
group by 1
order by 1
2026-04-24 计算每个用户的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 1
2026-04-24 计算每个用户的RFM值(1) 
select cust_uid as user_id,
 datediff(curdate(),max(trx_dt)) as recency,
 count(cust_uid) as frequency,
 sum(trx_amt) as monetary
from mt_trx_rcd_f
group by cust_uid
order by 1
2026-04-24 直观对比两种频率计算的差异(F) 
with basedata as
(
select cust_uid,count(cust_uid) as transaction_count,
count(distinct trx_dt) as active_days_count	
from mt_trx_rcd_f
group by 1
order by 3 desc )
,
rankdata as
(
select 
cust_uid,
transaction_count,
rank() over(order by transaction_count desc) as transaction_rank,
active_days_count,
rank() over(order by active_days_count desc) as active_days_rank
from basedata)
select 
cust_uid,
transaction_count,
transaction_rank,
active_days_count,
active_days_rank,
cast(transaction_rank as signed) -cast(active_days_rank as signed) as rank_difference
from rankdata 
order by 6 desc,1 asc
2026-04-23 每月新增用户占比 
with basedata as(
select cust_uid,substr(trx_dt,1,7) as month,
mch_nm,
row_number()over(partition by mch_nm,cust_uid order by trx_dt) as rn
from mt_trx_rcd1
order by mch_nm,month
)
select mch_nm,month,
count(distinct cust_uid) as total_users,
count(distinct case when rn=1 then cust_uid else null end) as new_users,
round(count(distinct case when rn=1 then cust_uid else null end)/count(distinct cust_uid)*100,2) as new_user_ratio
from basedata
group by 1,2
having count(distinct case when rn=1 then cust_uid else null end)>0
2026-04-23 每月新增用户占比 
with basedata as 
(
select mch_nm,substr(trx_dt,1,7) as month,
cust_uid,
row_number() over(partition by mch_nm,cust_uid order by trx_dt) as rn
from mt_trx_rcd1
order by 1,2
)
select mch_nm,month,
 count(distinct cust_uid) as total_users,
 count(distinct case when rn=1 then cust_uid else null end) as new_users,
 round(coalesce(count(distinct case when rn=1 then cust_uid else null end),0)/count(distinct cust_uid)*100,2) as new_user_ratio
from basedata
group by 1,2
having count(distinct case when rn=1 then cust_uid else null end)>0
2026-04-23 每月新增用户占比 
with basedata as(
select cust_uid,substr(trx_dt,1,7) as month,mch_nm from mt_trx_rcd1)
,
newbasedata as(
select cust_uid,month,mch_nm,
first_value(month) over(partition by mch_nm,cust_uid order by month) as fmth,
case when month=first_value(month) over(partition by mch_nm,cust_uid order by month) then 'new' else '其他'end as type
from basedata)
,
newdata as(
select * from newbasedata
where type='new')
,
ttlcnt as (
select mch_nm,month,count(distinct cust_uid) as total_users
from basedata 
group by 1,2
order by 1,2
)
,
newcnt as(
select mch_nm,month,count(distinct cust_uid) as new_users
from newdata
group by 1,2
order by 1,2
)
select t.*,
n.new_users,
round(coalesce(n.new_users,0)/t.total_users*100,2) as new_user_ratio
from ttlcnt t 
left join newcnt n on t.mch_nm=n.mch_nm and t.month=n.month 
where n.new_users is not null
2026-04-23 二级菜系复购率 
with basedata as(
select cust_uid,year(trx_dt) as year,mch_typ2
from mt_trx_rcd1
)
,
rpdata as(
select cust_uid,year,mch_typ2,count(*) as cnt
from basedata
group by 1,2,3
having count(*)>=2
)
,
ttlcnt as (
select mch_typ2,year,count(distinct cust_uid) as total_users
from basedata 
group by 1,2
order by 1,2
)
,
rpcnt as(
select mch_typ2,year,count(distinct cust_uid) as repeat_users
from rpdata
group by 1,2
order by 1,2
)
select t.*,r.repeat_users,
 round(coalesce(repeat_users,0)/total_users*100,2) as repurchase_rate
from ttlcnt t 
left join rpcnt r on t.mch_typ2=r.mch_typ2
2026-04-23 餐厅的用户复购率 
with basedata as(
select cust_uid,year(trx_dt) as yr,mch_nm from mt_trx_rcd1 order by mch_nm)
,
rpdata as(
select mch_nm,yr,cust_uid,count(*) as cnt
from basedata
group by 1,2,3
having cnt>=2)
,
ttlcnt as(
select mch_nm,yr as year,count(distinct cust_uid) as total_users
from basedata
group by 1,2
order by 1,2)
,
rpcnt as(
select mch_nm,yr as year,count(distinct cust_uid) as repeat_users
from rpdata
group by 1,2
order by 1,2
)
select t.*,
r.repeat_users,
round(coalesce(repeat_users,0)/total_users*100,2) as repurchase_rate
from ttlcnt as t 
left join rpcnt as r on t.mch_nm=r.mch_nm
2026-04-23 餐厅的客单价增长趋势 
with mthbase as (
 select substr(trx_dt,1,7) as month,
 trx_amt as amt,
 mch_nm,
 trx_seq
 from mt_trx_rcd1
 ),
avgamt as(
select mch_nm,month,sum(amt)/count(trx_seq) as avg_spending
from mthbase 
group by 1,2
order by mch_nm,month
)
select *,
round((avg_spending/lag(avg_spending) over(partition by mch_nm order by month)-1)*100,2) as growth_rate
from avgamt
2026-04-20 找出所有以酒店为起点或终点的类别组合的最热门路线 
with basedata as(
select start_loc,end_loc,l1.loc_ctg as start_ctg,l2.loc_ctg as end_ctg,
count(*) as trip_count 
from didi_sht_rcd d 
inner join loc_nm_ctg l1 on d.start_loc=l1.loc_nm
inner join loc_nm_ctg l2 on d.end_loc=l2.loc_nm
where l1.loc_ctg='酒店'
or l2.loc_ctg='酒店'
group by 1,2,3,4)
select start_loc,end_loc,start_ctg,end_ctg,trip_count
from(
select *,
row_number() over(partition by start_ctg,end_ctg order by trip_count desc) as rk
from basedata) t where rk=1 
order by trip_count desc
2026-04-20 找出所有以酒店为起点的类别组合的最热门路线 
with basedata as (
select start_loc,end_loc,concat(start_loc,'-',end_loc,l2.loc_ctg) as line,l2.loc_ctg
from didi_sht_rcd d
inner join loc_nm_ctg l1 on d.start_loc=l1.loc_nm 
inner join loc_nm_ctg l2 on d.end_loc=l2.loc_nm
where l1.loc_ctg = '酒店'
)
select start_loc,end_loc,loc_ctg,cnt as trip_count
from (
select *,
 row_number()over(partition by loc_ctg order by cnt desc) as rk
from(
select *
from (
Select start_loc,end_loc,loc_ctg,
count(line) over(partition by loc_ctg,line) as cnt
from basedata) t ) t2
group by 1,2,3,4) t3 
where rk=1
order by 4 desc