排名

用户解题统计

过去一年提交了

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

收藏

收藏日期 题目名称 解决状态
2026-02-03 超过3个标签的视频  未解决
2026-02-02 抖音面试真题(1)T+1日留存率  已解决
2026-02-02 直观对比两种频率计算的差异(F)  未解决
2026-02-02 得物面试真题(4)首单Mac二单iPhone的客户  已解决
2026-02-02 各班第一名  已解决
2026-02-02 先收藏后购买的用户数  已解决
2026-02-02 给商品打四类标签(列)  已解决

评论笔记

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

提交记录

提交日期 题目名称 提交代码
2026-02-05 时间日期(3)按月统计日花费,一天都不要浪费 
select substr(trx_time, 1, 7) as trx_mon 
 ,last_day(max(trx_time)) as last_day
 ,day(last_day(max(trx_time))) as days_of_mon
 ,sum(trx_amt) as trx_amt
 ,count(1) as trx_cnt
 ,sum(trx_amt) / day(last_day(max(trx_time))) as avg_day_amt
 ,count(1) / day(last_day(max(trx_time))) as avg_day_cnt
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
where usr_id = 5201314520
and year(trx_time) in (2023, 2024)
and mch_typ = '休闲娱乐'
group by substr(trx_time, 1, 7);
2026-02-05 时间日期(2)按月统计日花费,一天都不要浪费 
select substr(trx_time, 1, 7) as trx_mon 
 ,last_day(max(trx_time)) as last_day
 ,day(last_day(max(trx_time))) as days_of_mon
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
where usr_id = 5201314520
and year(trx_time) in (2023, 2024)
and mch_typ = '休闲娱乐'
group by substr(trx_time, 1, 7);
2026-02-05 时间日期(2)按月统计日花费,一天都不要浪费 
select substr(trx_time, 1, 7) as trx_mon 
 ,last_day(max(trx_time)) as last_day
 ,day(last_day(max(trx_time))) as days_of_mon
 ,sum(trx_amt) as trx_amt
 ,count(1) as trx_cnt
 ,sum(trx_amt) / day(last_day(max(trx_time))) as avg_day_amt
 ,count(1) / day(last_day(max(trx_time))) as avg_day_cnt
from cmb_usr_trx_rcd 
where usr_id = 5201314520
and year(trx_time) in (2023, 2024)
group by substr(trx_time, 1, 7);
2026-02-05 表连接(4)渣男把钱花在哪儿,维表可以来帮忙 
select typ.mch_typ 
 ,count(1) as trx_cnt
 ,sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
where rcd.usr_id = '5201314520'
and year(rcd.trx_time) = 2024
group by typ.mch_typ
2026-02-05 表连接(4)渣男把钱花在哪儿,维表可以来帮忙 
select typ.mch_typ 
 ,count(1) as trx_cnt
 ,sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
where rcd.usr_id = '5201314520'
group by typ.mch_typ
2026-02-05 表连接(4)渣男把钱花在哪儿,维表可以来帮忙 
select typ.mch_typ 
 ,count(1) as trx_cnt
 ,sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd rcd
left join cmb_mch_typ typ
on rcd.mch_nm = typ.mch_nm
group by typ.mch_typ
2026-02-03 表连接(1)你们难道都去过?那就试试用InnerJoin 
select t1.mch_nm
from (
select distinct mch_nm
from cmb_usr_trx_rcd
where usr_id = 5201314520 and year(trx_time) = 2024
) t1
inner join (
select distinct mch_nm
from cmb_usr_trx_rcd
where usr_id = 5211314521 and year(trx_time) = 2024
) t2
on t1.mch_nm = t2.mch_nm
2026-02-03 子查询(1)玩的最嗨那天在做甚?要用Where子查询 
select
    *
from
    cmb_usr_trx_rcd
where
    trx_amt = (
        select max(trx_amt)
        from cmb_usr_trx_rcd
        where usr_id = '5201314520'
          and year(trx_time) = 2024
    )
    and usr_id = '5201314520'
    and year(trx_time) = 2024;
2026-02-03 字符串与通配符(2)好多关键词做规则,可以使用rlike 
select
    case 
        when mch_nm like '%按摩保健休闲%' then '按摩保健休闲'
        when lower(mch_nm) rlike '.*(按摩|保健|休闲|spa|养生|会所).*' then '按摩、保健、休闲、养生、SPA、会所'
    end as reg_rules,
    count(distinct mch_nm) as mch_cnt
from
    cmb_usr_trx_rcd
where mch_nm like '%按摩保健休闲%'
   or lower(mch_nm) rlike '.*(按摩|保健|休闲|spa|养生|会所).*'
group by reg_rules
order by mch_cnt desc;
2026-02-03 查询所有起点和终点都属于餐饮类别的行程 
with res_loc as (
	select loc_nm
from loc_nm_ctg
	where loc_ctg = '餐饮'
)
select * 
from didi_sht_rcd
where start_loc in (select loc_nm from res_loc) 
and end_loc in (select loc_nm from res_loc);
2026-02-03 总播放时长最长的视频 
SELECT 
    v.video_id, 
    v.title, 
    ROUND(SUM((TIMESTAMPDIFF(SECOND, u.start_time, u.end_time))) / 3600, 2) AS total_play_duration_hours
FROM 
    ks_video_inf v
JOIN 
    ks_video_wat_log u ON v.video_id = u.video_id
WHERE 
    u.start_time >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)
GROUP BY 
    v.video_id, v.title
ORDER BY 
    total_play_duration_hours DESC
LIMIT 5;
2026-02-03 小结(2)越花越多是死罪,按月统计Substr 
select substr(trx_time, 1, 7) as trx_mon
 ,count(1) as trx_cnt
 ,sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and substr(trx_time, 1, 10) between '2022-11-01' and '2024-12-31'
and (truncate(trx_amt, 0) like '%88' or truncate(trx_amt, 0) like '%98')
and trx_amt > 200
and (hour(trx_time) between 0 and 3 or hour(trx_time) = 23)
and mch_nm rlike '.*(足疗|保健|按摩|养生|SPA)*.'
group by trx_mon
order by trx_mon;
2026-02-03 字符串与通配符(1)名称里面有特服,可以使用通配符 
select count(distinct mch_nm) as mch_cnt
from cmb_usr_trx_rcd
where mch_nm like '%按摩保健休闲%';
2026-02-03 分类(1)姿势太多很过分,分类要用CaseWhen 
select case when trx_amt = 288 then '1.WithHand'
when trx_amt = 388 then '2.WithMimi'
when trx_amt = 588 then '3.BlowJobbie'
when trx_amt = 888 then '4.Doi'
when trx_amt = 1288 then '5.DoubleFly'
		else '6.other' end as ser_typ
 ,count(1) as trx_cnt
 ,min(date(trx_time)) as first_date
from cmb_usr_trx_rcd
where usr_id='5201314520' and mch_nm='红玫瑰按摩保健休闲'
group by ser_typ
order by ser_typ;
2026-02-03 分类(1)姿势太多很过分,分类要用CaseWhen 
select case when trx_amt = 288 then '1.WithHand'
when trx_amt = 388 then '2.WithMimi'
when trx_amt = 588 then '3.BlowJobbie'
when trx_amt = 888 then '4.Doi'
when trx_amt = 1288 then '5.DoubleFly'
		else 'other' end as ser_typ
 ,count(1) as trx_cnt
 ,min(date(trx_time)) as first_date
from cmb_usr_trx_rcd
where usr_id='5201314520' and mch_nm='红玫瑰按摩保健休闲'
group by ser_typ
order by ser_typ;
2026-02-03 分类(1)姿势太多很过分,分类要用CaseWhen 
select case when trx_amt = 288 then '1.WithHand'
when trx_amt = 388 then '2.WithMimi'
when trx_amt = 588 then '3.BlowJobbie'
when trx_amt = 888 then '4.Doi'
when trx_amt = 1288 then '5.DoubleFly'
		else 'other' end as ser_typ
 ,count(1) as trx_cnt
 ,min(date(trx_time)) as first_date
from cmb_usr_trx_rcd
group by ser_typ
order by ser_typ;
2026-02-03 分组与聚合函数(6)想知道渣男有多坏,疯狂使用GroupBy 
select usr_id
 ,mch_nm
 ,sum(trx_amt) as trx_amt
 ,count(1) as trx_cnt
 ,min(trx_time) as first_time
from cmb_usr_trx_rcd
where usr_id = 5201314520 and trx_amt >= 288
group by usr_id, mch_nm;
2026-02-03 分组与聚合函数(5)想知道何时成瘾,用Max Or Min? 
select usr_id, min(trx_time) as first_time, mch_nm
from cmb_usr_trx_rcd
where usr_id = 5201314520 and mch_nm = '红玫瑰按摩保健休闲'
group by usr_id, mch_nm;
2026-02-03 分组与聚合函数(5)五花八门的项目,其实都有固定套路(2) 
select trx_amt
 ,count(1) as total_trx_cnt
 ,count(distinct usr_id) as unique_usr_cnt
 ,count(1) / count(distinct usr_id) as avg_trx_per_user
from cmb_usr_trx_rcd
where mch_nm = '红玫瑰按摩保健休闲'
and substr(trx_time, 1, 10) between '2023-01-01' and '2024-06-30'
group by trx_amt
order by avg_trx_per_user desc
limit 5;
2026-02-02 从未被领取的优惠券 
select coupon_id
 ,coupon_type
 ,discount_rule
 ,valid_days
from coupons
where coupon_id not in (
select distinct coupon_id
from user_coupons
where get_time is not null
)