排名

用户解题统计

过去一年提交了

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

收藏

收藏日期 题目名称 解决状态
2025-05-25 2020年后上市的医药公司  已解决
2025-05-19 播放量最高的标签  已解决
2025-05-19 超过3个标签的视频  已解决
2025-05-19 北交所每年上市数量  已解决
2025-05-19 德州扑克起手牌-同花两高张  已解决
2025-05-19 统计字符长度  已解决
2025-05-19 快手面试真题(1)同时在线人数  已解决
2025-05-19 只买iPhone的用户  已解决
2025-05-19 10月1日后再也没活跃过的用户  已解决
2025-05-19 销售金额前10的商品信息(2)  已解决
2025-05-14 窗口函数(7)三天吃四餐,你特么是不是乔杉?  已解决
2025-05-14 窗口函数(6)隔三差五去召妓,统计间隔用偏移  已解决
2025-05-14 窗口函数(5)越来越喜欢召妓,窗口函数用累计(3)  已解决
2025-05-12 窗口函数(1)年度前三和每月前三,搞懂排序窗口函数  已解决
2025-05-12 时间日期(6)爽完来根事后烟,不羡鸳鸯不羡仙  已解决
2025-05-11 时间日期(5)三腿爱往会所走,全当良心喂了狗  已解决
2025-05-09 表连接(2)渣男去过我对象没去过,那就用LeftJoin  已解决
2025-05-09 表连接(1)你们难道都去过?那就试试用InnerJoin  已解决
2025-05-09 子查询(1)玩的最嗨那天在做甚?要用Where子查询  已解决
2025-05-09 小结(2)越花越多是死罪,按月统计Substr  已解决
2025-05-09 小结(1)大数据早就能扫黄,找足证据不慌张  已解决
2025-05-08 大结局(😊)渣男9月爽翻天,罪证送他去西天  已解决
2025-05-07 窗口函数(4)越来越喜欢召妓,窗口函数用累计(2)  已解决
2025-05-01 窗口函数(3)越来越喜欢召妓,窗口函数用累计(1)  已解决
2025-05-01 时间日期(4)阶段综合-按月统计日花费,一天都不要浪费  已解决
2025-04-30 时间日期(3)按月统计日花费,一天都不要浪费  已解决
2025-04-29 时间日期(2)按月统计日花费,一天都不要浪费  已解决
2025-04-29 表连接(5)哪些没被分出来,用左用内你来猜  已解决
2025-04-29 表连接(4)渣男把钱花在哪儿,维表可以来帮忙  已解决
2025-04-29 基于共同兴趣爱好的餐厅推荐(6)-好基友(5)  已解决
2025-04-29 基于共同兴趣爱好的餐厅推荐(4)-好基友(2)  已解决
2025-04-28 基于共同兴趣爱好的餐厅推荐(3)-好基友(1)  已解决
2025-04-28 从未被领取的优惠券  已解决
2025-04-28 用户听歌完成情况  已解决
2025-04-27 最受欢迎歌手  已解决
2025-04-27 MJ最受欢迎的歌曲  未解决
2025-04-27 周杰伦的最受欢迎的专辑  已解决
2025-04-26 统计每个作者发布视频的平均互动指数  已解决
2025-04-24 各行业第一家上市公司  未解决
2025-04-22 横屏与竖屏视频的完播率(按AI配音和字幕分类)  已解决
2025-04-21 频道重合指数  未解决
2025-04-20 多类别观看指数计算  未解决
2025-04-20 对各品牌购买贡献度最高的三个关键词  未解决
2025-04-19 统计每个城市各状态的单量(行转列)  已解决
2025-04-19 统计每个城市各状态的单量  已解决
2025-04-18 计算每个城市的有效订单完成率  已解决
2025-04-17 从商品角度统计收藏到购买的转化率  已解决
2025-04-12 找出所有类别组合的最热门路线  已解决
2025-04-12 找出所有以酒店为起点或终点的类别组合的最热门路线  已解决
2025-04-12 找出所有以酒店为起点的类别组合的最热门路线  已解决
2025-04-11 找出酒店-餐饮的最热门路线  已解决
2025-04-09 查询所有起点和终点都属于餐饮类别的行程  已解决
2025-04-09 只被收藏未被购买的商品  已解决
2025-04-09 购买人数最多的商品类目  已解决
2025-04-04 文科潜力股  已解决
2025-04-03 小结-从不缺考的学生  已解决
2025-04-03 HAVING-语数英优异的学生  已解决
2025-04-03 HAVING-执教教师超过3人的科目  已解决
2025-04-03 CASE WHEN-男女学生的数量  已解决
2025-04-03 聚合函数-比较两位同学的数学成绩  已解决
2025-04-03 GROUP BY-年龄最大学生的出生日期  已解决
2025-04-03 条件过滤-没有职称的老教师  已解决
2025-04-03 字符串函数-查找任教5个班级的所有教师  已解决
2025-04-03 NULL的知识点  已解决
2025-04-02 数学成绩分段统计(3)  已解决
2025-03-30 数学成绩分段统计(2)  已解决
2025-03-27 各班第一名  已解决
2025-03-27 平均分最高的班级  已解决
2025-03-26 化学老师的教学成果  已解决
2025-03-22 优异物理成绩的分布  已解决
2025-03-21 经过第四象限的所有函数  未解决
2025-03-21 不经过第二象限的所有函数  已解决
2025-03-21 基于共同兴趣爱好的餐厅推荐(1)-我吃过啥  已解决
2025-03-21 A和K之间的手牌(1)  已解决
2025-03-20 大于J小于K的手牌  已解决
2025-03-20 语文数学英语至少1门超过100分的同学  已解决
2025-03-20 21世纪上市的银行  已解决
2025-03-19 查询播放量为0的歌手及其专辑  已解决
2025-03-19 用户听歌习惯的时间分布  已解决
2025-03-16 海王发红包  已解决
2025-03-16 接收红包金额绿茶榜  未解决
2025-03-16 至少两门科目大于等于110分的学生  已解决
2025-03-16 渣男腰子可真行,端午中秋干不停  已解决
2025-03-16 小结-行转列,展开学生成绩(1)  已解决
2025-03-12 HAVING-每次成绩都不低于80分的学生  已解决
2025-03-12 CASE WHEN-老中青教师数量  已解决
2025-03-12 条件过滤-查找2009年出生的女学生  已解决
2025-03-12 数学成绩分段统计(1)  已解决
2025-03-12 S1年级物理成绩前10名(1)  已解决
2025-03-12 S1年级物理成绩前10名(2)  已解决
2025-03-06 登录天数分布  未解决
2025-03-06 通勤、午休、临睡个时间段活跃人数分布  已解决
2025-03-04 上月活跃用户数  已解决
2025-03-03 一线城市历年平均气温  已解决
2025-03-03 多云天气天数  已解决
2025-03-03 德州扑克起手牌-最强起手牌KK+  已解决
2025-03-03 抖音面试真题(1)T+1日留存率  未解决

评论笔记

评论日期 题目名称 评论内容 站长评论
2025-05-19 德州扑克起手牌-同花两高张 
同花不应该是right(card1, 2) = right(card2, 2)吗?
select 
    right('2♠',1)
   输出什么?
2025-05-19 按歌手名字字符长度统计歌手个数 
字符长度不应该是char_length()吗
看题干 注意,“周杰伦”的字符长度应为9。
2025-05-19 快手面试真题(2)同时在线人数峰值 
没有限定在哪段时间内求峰值
没限定就是默认为全部哦
2025-05-19 10月1日后再也没活跃过的用户 
with login_before as (
  select
  	distinct usr_id
  from
  	user_login_log
  where
  	date(login_time) <= '2024-10-01'
),
login_after as (
  select
  	distinct usr_id
  from
  	user_login_log
  where
  	date(login_time) >= '2024-10-02'
)
select
	count(b.usr_id) - count(a.usr_id) as inactive_user_count
from 
	login_before b
left join
	login_after a on a.usr_id = b.usr_id
;
为什么不对呢?
还是你牛,你的是对的。更原始更直观。
2025-05-13 窗口函数(1)年度前三和每月前三,搞懂排序窗口函数 
有一处不解:在monthly_top_merchants里既使用group by 分组,又在over()里使用了partition by,岂不是按照 trx_mon、mch_nm分组之后再用trx_mon分组吗?为什么最终结果还是对的呢?
这说明你对窗口函数还没有真正理解。如果over()里不使用partition by,输出的是什么呢?

你多试试这样的题。每个月交易笔数前三的商户、每次考试每个年级每个班级物理前三名的用户。
2025-05-09 表连接(1)你们难道都去过?那就试试用InnerJoin 
这样写为什么结果和参考答案不一样呢?
select 
	distinct u1.mch_nm 
from 
	cmb_usr_trx_rcd u1 
inner join 
	cmb_usr_trx_rcd u2 on u1.mch_nm = u1.mch_nm
where
	year(u1.trx_time) = 2024
    and 
    year(u2.trx_time) = 2024
    and 
    u1.usr_id = 5201314520
    and 
    u2.usr_id = 5211314521
order by
	u1.mch_nm desc;
两个问题。1、你的连接条件是什么;2、你的where条件能识别出【都】去过吗
2025-04-29 基于共同兴趣爱好的餐厅推荐(4)-好基友(2) 
我搞错了,两家分别统计的结果相加应该=2,不是>=2
having
	count(distinct case when u1.mch_nm = '庄家界(千灯店)' then u1.cust_uid else null end) + count(distinct case when u1.mch_nm = '黄记烘培宫廷桃酥王' then u1.cust_uid else null end) = 2
啥也没说
2025-04-29 基于共同兴趣爱好的餐厅推荐(4)-好基友(2) 
我觉得我这种写法比较简洁。
在过滤cust_id_1的时候要满足用户两家店都去过,也就是两家店都能在mch_nm里找到,那么就应该分别对两家进行count,因为如果只是用 mch_nm in ('庄家界(千灯店)', '黄记烘培宫廷桃酥王') 来判断,那么只吃过其中一家(超过两次)的用户就会被计入。
select 
	u.cust_uid,
        u1.cust_uid as cust_uid_1
from 
	mt_trx_rcd1 u 
left join
	mt_trx_rcd1 u1 on u.cust_uid <> u1.cust_uid
where
	u.cust_uid = 'MT10000'
group by
	u.cust_uid,
        cust_uid_1
having
	count(distinct case when u1.mch_nm = '庄家界(千灯店)' then u1.cust_uid else null end) + count(distinct case when u1.mch_nm = '黄记烘培宫廷桃酥王' then u1.cust_uid else null end) >= 2; 
啥也没说
2025-04-27 MJ最受欢迎的歌曲 
with groupings as (
  select
  	so.album_id,
  	so.song_id,
  	so.song_name,
  	count(distinct r.user_id) as user_count,
  	count(r.user_id) as play_count
  from
  	singer_info si 
  inner join 
  	song_info so on so.origin_singer_id = si.singer_id
  inner join 
  	album_info a on so.album_id = a.album_id
  inner join 
  	listen_rcd r on r.song_id = so.song_id
  where
  	si.singer_name = 'Michael Jackson'
  group by
  	so.album_id,
  	so.song_id,
  	so.song_name
),
top_album as (
  select
  	album_id,
  	sum(user_count) as album_user_count
  from
  	groupings
  group by
  	album_id
  order by
  	album_user_count desc
  limit 1
)
select 
	g.song_name,
    sum(g.play_count) as total_play_count,
    sum(g.user_count) as total_user_count
from 
	top_album t 
inner join 
	groupings g on t.album_id = g.album_id
group by
	g.song_name 
order by
	total_play_count desc
limit 3;
啥也没说
2025-04-27 MJ最受欢迎的歌曲 
题干要求找到最受欢迎的“专辑”,参考答案没有涉及专辑,计算的是最受欢迎的歌曲
已修改
2025-04-24 横屏与竖屏视频的完播率(按AI配音和字幕分类) 
我在第一个子查询的group by里没有添加video_id,因为我觉得可以直接统计每个类别的观看用户数和观看至视频结束的用户数,但是这样计算并没有得到输出示例里的结果,p行的数据是对的,l行AI_with_hint no_AI_with_hint数据不对。为什么会这样?
with group_counting as (
  select
  	inf.screen_type,
  	inf.if_AI_talking,
  	inf.if_hint,
  	count(distinct case when timestampdiff(second, log.start_time, log.end_time) >= inf.duration then log.uid else null end) as finish_count,
  	count(distinct log.uid) as total_count
  from
  	ks_video_inf inf 
  inner join 
  	ks_video_wat_log log on log.video_id = inf.video_id
  group by
  	inf.screen_type,
  	inf.if_AI_talking,
  	inf.if_hint
)
select 
	screen_type,
    round(100 * max(case when if_AI_talking = 1 and if_hint = 1 then finish_count else 0 end) / nullif(max(case when if_AI_talking = 1 and if_hint = 1 then total_count end), 0), 2) as AI_with_hint,
    round(100 * max(case when if_AI_talking = 1 and if_hint = 0 then finish_count else 0 end) / nullif(max(case when if_AI_talking = 1 and if_hint = 0 then total_count end), 0), 2) as AI_no_hint, 
    round(100 * max(case when if_AI_talking = 0 and if_hint = 1 then finish_count else 0 end) / nullif(max(case when if_AI_talking = 0 and if_hint = 1 then total_count end), 0), 2) as no_AI_with_hint, 
    round(100 * max(case when if_AI_talking = 0 and if_hint = 0 then finish_count else 0 end) / nullif(max(case when if_AI_talking = 0 and if_hint = 0 then total_count end), 0), 2) as no_AI_no_hint
from 
	group_counting
group by
	screen_type;
再理解下这种写法:SELECT 
    i.screen_type,
    ROUND(COALESCE(
        SUM((TIMESTAMPDIFF(SECOND, l.start_time, l.end_time) >= i.duration) * (i.if_AI_talking = 1 AND i.if_hint = 1)) 
        * 100.0 
        / NULLIF(SUM(i.if_AI_talking = 1 AND i.if_hint = 1), 0), 
        0
    ), 2) AS AI_with_hint,
    ROUND(COALESCE(
        SUM((TIMESTAMPDIFF(SECOND, l.start_time, l.end_time) >= i.duration) * (i.if_AI_talking = 1 AND i.if_hint = 0)) 
        * 100.0 
        / NULLIF(SUM(i.if_AI_talking = 1 AND i.if_hint = 0), 0), 
        0
    ), 2) AS AI_no_hint,
    ROUND(COALESCE(
        SUM((TIMESTAMPDIFF(SECOND, l.start_time, l.end_time) >= i.duration) * (i.if_AI_talking = 0 AND i.if_hint = 1)) 
        * 100.0 
        / NULLIF(SUM(i.if_AI_talking = 0 AND i.if_hint = 1), 0), 
        0
    ), 2) AS no_AI_with_hint,
    ROUND(COALESCE(
        SUM((TIMESTAMPDIFF(SECOND, l.start_time, l.end_time) >= i.duration) * (i.if_AI_talking = 0 AND i.if_hint = 0)) 
        * 100.0 
        / NULLIF(SUM(i.if_AI_talking = 0 AND i.if_hint = 0), 0), 
        0
    ), 2) AS no_AI_no_hint
FROM 
    ks_video_inf i
JOIN 
    ks_video_wat_log l ON i.video_id = l.video_id
GROUP BY 
    i.screen_type;。这个是最直接的,没有弯弯绕绕的多次计算。你写的相当于多了一次去重。把分子分母都搞小了。
2025-04-21 各班第一名 
这题容易在最后一步忘记限定考试日期
啥也没说
2025-04-21 优异物理成绩的分布 
这一题好像比较容易忽略教师的科目还是要限制的
啥也没说
2025-04-20 对各品牌购买贡献度最高的三个关键词 
为什么参考答案不关联点击记录表?如果没有不关联点击记录表,应该就没有办法限定用户是按照“搜索——点击——购买”的流程消费的吧?万一用户在同一个session当中既搜索了关键词又从搜索结果以外的地方点击页面购买商品呢?
手动点赞!你这才算是深入理解了漏斗。漏斗需要人来定义的,你的是灰常严格的定义👍
2025-04-18 计算每天的有效订单完成率 
参考答案末尾 ORDER BY completion_rate DESC; 
但是输出示例似乎是按照日期排序的
啥也没说
2025-04-18 计算每个城市的有效订单完成率 
用一次group by 可以同时计算出订单总数和有效订单数,count(*) count(case when……)
啥也没说
2025-04-18 从商品角度统计收藏到购买的转化率 
使用两表联合,条件是商品id相等和用户ID相等,但是在where语句里过滤收藏时间早于购买时间却产生了奇怪的结果:收藏用户和购买用户数量相等了。代码如下:
with purchase_cnt as (
  select
  	f.mch_id,
  	count(distinct f.cust_uid) as fav_user_cnt,
  	count(distinct p.cust_uid) as pcs_user_cnt
  from
  	xhs_fav_rcd f 
  left join 
  	xhs_pchs_rcd p on p.mch_id = f.mch_id and p.cust_uid = f.cust_uid 
  where
  	p.pchs_tm > f.fav_tm
  group by
  	f.mch_id
)

select 
	mch_id,
    fav_user_cnt,
    pcs_user_cnt,
    round(100 * cast(pcs_user_cnt as float) / fav_user_cnt, 2) as convert_rate
from 
	purchase_cnt
group by
	mch_id,
    fav_user_cnt,
    pcs_user_cnt
order by
	convert_rate desc;
后来把 p.pchs_tm > f.fav_tm 写在了on里面 on p.mch_id = f.mch_id and p.cust_uid = f.cust_uid and p.pchs_tm > f.fav_tm,结果就都对了。为什么会这样?
啥也没说
2025-04-12 找出所有类别组合的最热门路线 
为什么这里用danse_rank?
啥也没说
2025-04-12 找出所有类别组合的最热门路线 
group by 的参数有很多时,group by 是怎样分组的呢?我们想让它以start_ctg和end_ctg分组,但是r.start_loc和r.end_loc不会干扰吗?
啥也没说
2025-04-10 查询所有起点和终点都属于餐饮类别的行程 
起点是餐饮、终点是餐饮两个子查询,同时在两个集合中的地点:id相同,且时间相同
with start_catering as (
  select
  	r.cust_uid,
  	r.start_loc,
  	r.end_loc,
  	r.start_tm,
  	r.car_cls
  from
  	didi_sht_rcd r 
  inner join
  	loc_nm_ctg l on l.loc_nm = r.start_loc
  where
  	l.loc_ctg = '餐饮'
),
end_catering as (
  select
  	r.cust_uid,
  	r.start_loc,
  	r.end_loc,
  	r.start_tm,
  	r.car_cls
  from
  	didi_sht_rcd r 
  inner join 
  	loc_nm_ctg l on l.loc_nm = r.end_loc
  where
  	l.loc_ctg = '餐饮'
)
select 
	s.* 
from 
	start_catering s 
inner join 
	end_catering e on s.cust_uid = e.cust_uid and s.start_tm = e.start_tm
order by
	s.start_tm asc
;
啥也没说
2025-04-09 只被收藏未被购买的商品 
这一题如果用DISTINCT怎么做呢?
啥也没说
2025-04-05 化学老师的教学成果 
select 
	t.name,
    count(distinct s.student_id) as total_stu,
    count(distinct (case when sc.score < 60 then s.student_id else null end)) as unpass_stu,
    count(distinct case when sc.score < 60 then s.student_id else null end) / count(distinct s.student_id) as up_rate
from students s 
inner join 
	teachers t on t.class_code like concat('%', s.class_code, '%')
inner join
	scores sc on s.student_id = sc.student_id
where
	t.subject = '化学'
group by
	t.name
;

这样写有问题吗?未及格学生人数和正确结果有1-3的误差,不知为什么。
仔细阅读你的链接条件,化学老师所带班级的学生成绩,你这样是把所有科目成绩都算进去了。要么在case when条件里加一个sc.subject='化学',要么在where 条件里过滤出化学成绩。
2025-04-03 小结-从不缺考的学生 
select 
	student_id
from scores 
group by
	student_id
having
	count(exam_date) = count(score)
order by
	student_id;
啥也没说
2025-04-03 字符串函数-查找任教3个班级的所有教师 
select 
	name,
    subject,
    class_code
from 
	teachers 
where 
	class_code like 'C___C___C___'
order by
	name asc;
啥也没说
2025-04-03 字符串函数-查找任教5个班级的所有教师 
select 
	name,
    subject,
    class_code
from 
	teachers 
where
	class_code like 'C___C___C___C___C___'
order by
	name asc;
 
啥也没说
2025-04-02 数学成绩分段统计(3) 
with score_ranges as (
  select 
  	st.class_code,
  	count(*) as class_total, 
	sum(case when sc.score >= 110 then 1 else 0 end) as excellent,
    sum(case when sc.score between 90 and 109 then 1 else 0 end) as good,
    sum(case when sc.score between 60 and 89 then 1 else 0 end) as pass,
    sum(case when sc.score < 60 then 1 else 0 end) as fail
  from
  	students st
  inner join
  	scores sc on sc.student_id = st.student_id
  where
  	exam_date = '2024-06-30' and sc.subject = '数学'
  group by
  	st.class_code
)
select 
	class_code,
    class_total,
    concat(excellent, ' ,', round(100 * excellent / class_total, 2), '%') as excellent,
    concat(good, ' ,', round(100 * good / class_total, 2), '%') as good,
    concat(pass, ' ,', round(100 * pass / class_total, 2), '%') as pass,
    concat(fail, ' ,', round(100 * fail / class_total, 2), '%') as fail
from score_ranges
group by class_code
order by class_code;
 
啥也没说
2025-04-02 数学成绩分段统计(2) 
with total_levels as (
  select 
  	student_id,
  	(case when score >= 110 then 1 else 0 end) as excellent,
  	(case when score between 90 and 109 then 1 else 0 end) as good,
  	(case when score between 60 and 89 then 1 else 0 end) as pass,
  	(case when score < 60 then 1 else 0 end) as fail
  from scores
  where exam_date = '2024-06-30' and subject = '数学'
)
select 
	s.class_code,
    sum(excellent) as excellent,
    sum(good) as good,
    sum(pass) as pass,
    sum(fail) as fail
from 
	total_levels as t 
inner join 
	students as s on s.student_id = t.student_id
group by
	s.class_code
order by
	s.class_code;
啥也没说
2025-03-30 数学成绩分段统计(1) 
这题只要scores一个表就行了吧?
case when好像会短路,所以要从大数往小了判断
短路这个词用的好啊。关于短路,你再研究研究,要是我就想从小到大来写,又该怎么办呢?(理论上只需要保证所有条件符合MECE原则,管你怎么写,都能算出来)
2025-03-21 经过第四象限的所有函数 
a=0,b>0时,c是否应该>0才能经过第二象限?
a>0时,是否不需要其他条件曲线都能经过第二象限?
select * 
from numbers_for_fun 
where
	(
      a = 0 and
      (
        (b > 0 and c > 0)
        or 
        (b < 0)
        or 
        (b = 0 and c < 0)
      )
    ) 
    or a > 0
    or (
      a < 0 and 
      (
        (b > 0 and c > 0)
        or 
        (b < 0 and c > b*b/4/a)
      )
    );
只有你在认真刷题。我忘改标题了,是经过第【四】象限的所有函数
2025-03-21 基于共同兴趣爱好的餐厅推荐(1)-我吃过啥 
select 
    distinct cust_uid, 
    mch_nm 
from mt_trx_rcd1 
where cust_uid = 'MT10000'
order by mch_nm;
也可以
是的。
deepseek询问 distinct 和group by哪个效率更高,分别使用什么场景,让自己再多学一点知识
2025-03-21 经过至少两个象限的一元一次函数 
c = 0 直线也可以经过两个象限啊
只要是一元一次函数,他一定经过至少两个象限是不?
2025-03-21 找出与X轴交点大于0的一元一次函数 
select * 
from numbers_for_fun 
where
	a = 0 
    and 
    b <> 0
    -(c/b) > 0
order by id;
直线与x轴的交点:bx+c=0, 那么x=-(c/b)。应该是这样的吧?
 -(c/b) > 0 跟参考答案的条件是一样的哦
2025-03-20 查询播放量为0的歌手及其专辑 
song_info 要用left join,是因为有些歌手或专辑可能没有歌曲在线?我用inner join最终没有结果。所以“播放量为0”包含了“有歌曲在线无播放记录”和“歌手的歌曲不在线因此无从播放”两个子集?
这题考的就是inner join和left join的使用场景。你运行这段代码试试,SELECT 
    s.singer_id,
    s.singer_name,
    a.album_id,
    a.album_name,
    COUNT(l.id) AS play_count
FROM 
    singer_info s
JOIN 
    album_info a ON s.singer_id = a.singer_id
inner JOIN 
    song_info sg ON a.album_id = sg.album_id
inner JOIN 
    listen_rcd l ON sg.song_id = l.song_id
GROUP BY 
    s.singer_id, s.singer_name, a.album_id, a.album_name。
2025-03-16 接收红包金额绿茶榜 
参考答案和输出示例给出的是接收红包的用户的id,但是题设给的要求是发出红包用户id。
而且参考答案里的year(rcv_datetime) != 1900也不知所谓。
啥也没说
2025-03-16 至少两门科目大于等于110分的学生 
sum(
   case
      when chinese >= 110 then 1 
      when math >= 110 then 1
      when english >= 110 then 1
      else 0
   end
) >= 2
这种判断不能按预想的执行,因为case when 短路了,第一个条件执行完后面的就不判断了,所以sum永远不能得到2
啥也没说
2025-03-16 至少两门科目大于等于110分的学生 
sum(
 case 
when
)
啥也没说
2025-03-04 国庆假期后第一天涨幅高于1%的股票 
涨跌幅如果是按照给出的公式计算的话,应该是小于1的小数吧,不是百分比吧?
啥也没说
2025-03-03 滴滴面试真题(2)打车订单呼叫应答时间 
有很多订单有应答后面又被取消了,所以应答时间和是否取消订单没关系啊
啥也没说
2025-02-26 分类(1)姿势太多很过分,分类要用CaseWhen 
提问:SQL语句的执行顺序不是from-where-group by-having-select吗?为什么在select里声明的ser_typ可以用在group by里呢?执行group by的时候SQL怎么知道有ser_typ?
还有一个隐藏的动作 execute(执行),select你可以理解为渲染、挑选,把执行后的结果捡出来,捡的实际动作就是纯捡,不产生任何新的字段。
2025-02-24 条件过滤(2)半夜活动有猫腻,Hour函数给给力 
对日期使用 between and 不是默认两个边界值都是0点吗?between '2024-09-01' and '2024-09-30'就是2024-09-01 00:00:00到2024-09-30 00:00:00,那么如果表里有9月30号0点以后的记录也不会被查询到了?
是的 看第一题 你可以实验一下

提交记录

提交日期 题目名称 提交代码
2025-05-25 2020年后上市的医药公司 
select 
	year(list_date) as year,
	count(1) as number
from 
	stock_info 
where
	year(list_date) in (2020, 2021, 2022, 2023, 2024)
and
name rlike '医|药|生物'
group by
	year
order by
	year;
2025-05-25 2020年后上市的医药公司 
select 
	year(list_date) as year,
	count(1) as number
from 
	stock_info 
where
	year(list_date) in (2020, 2021, 2022, 2023, 2024)
and
name rlike '.*(医|药|生物).*'
group by
	year
order by
	year;
2025-05-25 2020年后上市的医药公司 
select 
	year(list_date) as year,
	count(1) as number
from 
	stock_info 
where
	year(list_date) in (2021, 2022, 2023, 2024)
and
name rlike '[医|药|生物]'
group by
	year
order by
	year;
2025-05-25 统计特定行业内的公司名长度分布 
select 
	industry,
avg(length(name)) as avg_length,
max(length(name)) as max_length,
min(length(name)) as min_length
from 
	stock_info 
where
	industry in ('通信设备', '生物制药', '旅游景点', '医疗保健', '食品')
group by
	industry
order by
	industry;
2025-05-25 统计特定行业内的公司名长度分布 
select 
	industry,
avg(char_length(name)) as avg_length,
max(char_length(name)) as max_length,
min(char_length(name)) as min_length
from 
	stock_info 
where
	industry in ('通信设备', '生物制药', '旅游景点', '医疗保健', '食品')
group by
	industry
order by
	industry;
2025-05-25 各地区包含“中国”或“中”字开头的公司数量及比例 
with area_grouping as (
select
	area,
	count(1) as total_companies,
	sum(case when name like '中%' or name like '%中国%' then 1 else 0 end) as china_named_companies
from
	stock_info
group by
	area
)
select
	*,
round(china_named_companies / total_companies, 3) as proportion
from 
	area_grouping
order by
	proportion desc
limit 5;
2025-05-25 各地区包含“中国”或“中”字开头的公司数量及比例 
SELECT 
    area,
    COUNT(*) AS total_companies,
    SUM(CASE WHEN name LIKE '%中国%' OR name LIKE '中%' THEN 1 ELSE 0 END) AS chinese_named_companies,
    ROUND(SUM(CASE WHEN name LIKE '%中国%' OR name LIKE '中%' THEN 1 ELSE 0 END) / COUNT(*),3) AS proportion
FROM stock_info
GROUP BY area
ORDER BY 4 desc
limit 5;
2025-05-25 各地区包含“中国”或“中”字开头的公司数量及比例 
with area_grouping as (
select
	area,
	sum(case when name like '中%' or name like '%中国%' then 1 else 0 end) as china_named_companies,
	count(1) as total_companies
from
	stock_info
group by
	area
)
select
	*,
round(china_named_companies / total_companies, 3) as proportion
from 
	area_grouping
order by
	proportion desc
limit 5;
2025-05-25 每个行业最早上市的公司 
with industry_rank as (
select
	*,
	row_number() over(partition by industry order by list_date asc) as rnk
from
	stock_info
where
	name like '中国%' or name like '%中%'
)
select 
	ts_code,
symbol,
name,
area,
industry,
list_date
from 
	industry_rank 
where
	rnk = 1
order by
	industry;
2025-05-24 中字头上市企业 
select 
	count(1) as number
from stock_info 
where
	(name rlike '^中' or name like '%华%')
and
industry in ('通信设备', '生物制药', '旅游景点', '医疗保健', '食品') ;
2025-05-24 播放量最高的标签 
with generator25 as (
select @xi:=@xi+1 as xc from
	(select 1 union all select 2 union all select 3 union all select 4 union all select 5) xc1,
	(select 1 union all select 2 union all select 3 union all select 4 union all select 5) xc2,
	(select @xi:=0) xc0
),
max_tag_number as (
select
	max(char_length(tag) - char_length(replace(tag, ' ', '')) + 1) as max_tag
from 
	ks_video_inf
),
limit_xc as (
select
	xc
from
	generator25 i, max_tag_number n
where
	xc <= n.max_tag
),
split_tags as (
select
	v.video_id,
	trim(substring_index(substring_index(v.tag, ' ', i.xc), ' ', -1)) as tag
from
	ks_video_inf as v
inner join 
 	limit_xc as i on i.xc <= char_length(v.tag) - char_length(replace(v.tag, ' ', '')) + 1
)
select
	t.tag,
count(1) as total_plays
from
	split_tags t 
inner join 
	ks_video_wat_log l on l.video_id = t.video_id
where
	l.start_time >= date_sub(current_date, interval 1 month)
group by
	t.tag
order by
	total_plays desc,
t.tag
limit 1;
2025-05-24 播放量最高的标签 
with generator25 as (
select @xi:=@xi+1 as xc from
	(select 1 union all select 2 union all select 3 union all select 4 union all select 5) xc1,
	(select 1 union all select 2 union all select 3 union all select 4 union all select 5) xc2,
	(select @xi:=0) xc0
),
max_tag_number as (
select
	max(char_length(tag) - char_length(replace(tag, ' ', '')) + 1) as max_tag
from 
	ks_video_inf
),
limit_xc as (
select
	xc
from
	generator25 i, max_tag_number n
where
	xc <= n.max_tag
),
split_tags as (
select
	v.video_id,
	trim(substring_index(substring_index(v.tag, ' ', i.xc), ' ', -1)) as tag
from
	ks_video_inf as v
inner join 
 	limit_xc as i on i.xc <= char_length(v.tag) - char_length(replace(v.tag, ' ', '')) + 1
)
select
	t.tag,
count(1) as total_plays
from
	split_tags t 
inner join 
	ks_video_wat_log l on l.video_id = t.video_id
where
	l.start_time >= date_sub(current_date, interval 1 month)
group by
	t.tag
order by
	total_plays desc
limit 2;
2025-05-24 播放量最高的标签 
with generator25 as (
select @xi:=@xi+1 as xc from
	(select 1 union all select 2 union all select 3 union all select 4 union all select 5) xc1,
	(select 1 union all select 2 union all select 3 union all select 4 union all select 5) xc2,
	(select @xi:=0) xc0
),
max_tag_number as (
select
	max(char_length(tag) - char_length(replace(tag, ' ', '')) + 1) as max_tag
from 
	ks_video_inf
),
limit_xc as (
select
	xc
from
	generator25 i, max_tag_number n
where
	xc <= n.max_tag
),
split_tags as (
select
	v.video_id,
	trim(substring_index(substring_index(v.tag, ' ', i.xc), ' ', -1)) as tag
from
	ks_video_inf as v
inner join 
 	limit_xc as i on i.xc <= char_length(v.tag) - char_length(replace(v.tag, ' ', '')) + 1
)
select
	t.tag,
count( l.uid) as total_plays
from
	split_tags t 
inner join 
	ks_video_wat_log l on l.video_id = t.video_id
where
	l.start_time >= date_sub(current_date, interval 1 month)
group by
	t.tag
order by
	total_plays desc
limit 1;
2025-05-24 播放量最高的标签 
with generator25 as (
select @xi:=@xi+1 as xc from
	(select 1 union all select 2 union all select 3 union all select 4 union all select 5) xc1,
	(select 1 union all select 2 union all select 3 union all select 4 union all select 5) xc2,
	(select @xi:=0) xc0
),
max_tag_number as (
select
	max(char_length(tag) - char_length(replace(tag, ' ', '')) + 1) as max_tag
from 
	ks_video_inf
),
limit_xc as (
select
	xc
from
	generator25 i, max_tag_number n
where
	xc <= n.max_tag
),
split_tags as (
select
	v.video_id,
	trim(substring_index(substring_index(v.tag, ' ', i.xc), ' ', -1)) as tag
from
	ks_video_inf as v
inner join 
 	limit_xc as i on i.xc <= char_length(v.tag) - char_length(replace(v.tag, ' ', '')) + 1
)
select
	t.tag,
count(distinct l.uid) as total_plays
from
	split_tags t 
inner join 
	ks_video_wat_log l on l.video_id = t.video_id
where
	l.start_time >= date_sub(current_date, interval 1 month)
group by
	t.tag
order by
	total_plays desc
limit 1;
2025-05-19 超过3个标签的视频 
select 
	video_id,
title,
author_id, 
tag
from 
	ks_video_inf 
where
	char_length(tag) - char_length(replace(tag, ' ', '')) > 2
order by
	video_id asc;
2025-05-19 超过3个标签的视频 
select 
	video_id,
title,
author_id, 
tag
from 
	ks_video_inf 
where
	char_length(tag) - char_length(replace(tag, ' ', '')) >= 2
order by
	video_id asc;
2025-05-19 北交所每年上市数量 
select 
	year(list_date) as Y,
count(distinct ts_code) as cnt
from stock_info 
where
	ts_code like '%BJ'
and 
year(list_date) >= 2020 and year(list_date) <= 2024
group by
	Y
order by
	Y;
2025-05-19 北交所每年上市数量 
select 
	year(list_date) as Y,
count(distinct ts_code) as cnt
from stock_info 
where
	area = '北京'
and 
year(list_date) >= 2020 and year(list_date) <= 2024
group by
	Y
order by
	Y;
2025-05-19 北交所每年上市数量 
select 
	year(list_date) as Y,
count(ts_code) as cnt
from stock_info 
where
	area = '北京'
and 
year(list_date) >= 2020 and year(list_date) <= 2024
group by
	Y
order by
	Y;
2025-05-19 德州扑克起手牌-同花两高张 
select 
	count(case when right(card1, 1) = right(card2, 1)
 and (left(card1, 1) in ('J', 'K', 'Q', 'A'))
 and (left(card2, 1) in ('J', 'K', 'Q', 'A'))
 then id else null end) / 2 as cnt,
count(1) / 2 as ttl_cnt,
count(case when right(card1, 1) = right(card2, 1)
 and (left(card1, 1) in ('J', 'K', 'Q', 'A'))
 and (left(card2, 1) in ('J', 'K', 'Q', 'A'))
 then id else null end) / count(1) as p
from hand_permutations 
;