排名

用户解题统计

过去一年提交了

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

收藏

收藏日期 题目名称 解决状态
没有收藏的题目。

评论笔记

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

提交记录

提交日期 题目名称 提交代码
2025-02-07 抖音面试真题(1)T+1日留存率 
with data1 as (
    select distinct 
        usr_id,
        date(login_time) as login_date 
    from 
        user_login_log 
    where 
        datediff(current_date, date(login_time)) <= 30
),
data2 as (
    select 
        T.usr_id, 
        T.login_date as T_date, 
        T_1.login_date as T_1_date 
    from 
        data1 as T 
    left join 
        data1 as T_1 
    on 
        T.usr_id = T_1.usr_id 
        and datediff(T.login_date, T_1.login_date) = -1
)
select 
    T_date as first_login_date, 
    concat(round(avg(T_1_date is not null)*100, 2), '%') as T1_retention_rate 
from 
    data2 
group by 
    T_date 
order by 
    T_date;
2025-02-07 小结-行转列,展开学生成绩(1) 
SELECT 
    exam_date,
    MAX(CASE WHEN subject = '语文' THEN score ELSE NULL END) AS chinese_score,
    MAX(CASE WHEN subject = '数学' THEN score ELSE NULL END) AS math_score,
    MAX(CASE WHEN subject = '英语' THEN score ELSE NULL END) AS english_score
FROM scores
WHERE student_id = 460093
GROUP BY exam_date
ORDER BY exam_date;
2025-02-07 一线城市历年平均气温 
select year(dt) as Y
    ,cast(avg(case when city='beijing' then tmp_h else null end) as decimal(4,2)) as '北京'
    ,cast(avg(case when city='shanghai' then tmp_h else null end) as decimal(4,2)) as 上海
    ,cast(avg(case when city='shenzhen' then tmp_h else null end) as decimal(4,2)) as 深圳
    ,cast(avg(case when city='guangzhou' then tmp_h else null end) as decimal(4,2)) as 广州
from
    weather_rcd_china
where 
    year(dt) between 2011 and 2022
group by 
    year(dt)
2025-02-07 字符串与通配符(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;
2025-02-07 字符串与通配符(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;
2025-02-07 字符串与通配符(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;
2025-02-07 字符串与通配符(1)名称里面有特服,可以使用通配符 
select count(distinct mch_nm) mch_cnt
from cmb_usr_trx_rcd 
where mch_nm like'%按摩保健休闲%'
2025-02-07 字符串与通配符(1)名称里面有特服,可以使用通配符 
select count(mch_nm) mch_cnt
from cmb_usr_trx_rcd 
where mch_nm like'%按摩保健休闲%'
2025-02-07 字符串与通配符(1)名称里面有特服,可以使用通配符 
select count(mch_nm) mch_cnt
from cmb_usr_trx_rcd 
where mch_nm like'%按摩保健休闲'
2025-02-07 分类(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(trx_amt) 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
2025-02-07 分类(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(trx_amt) 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 1
2025-02-07 分类(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(*) 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 1
2025-02-07 分类(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 1
2025-02-07 分类(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(trx_amt) trx_cnt,
min(trx_time) first_date
from cmb_usr_trx_rcd 
group by 1
ORDER BY 
CASE 
WHEN ser_typ = '1.WithHand' THEN 1
WHEN ser_typ = '2.WithMimi' THEN 2
WHEN ser_typ = '3.BlowJobbie' THEN 3
WHEN ser_typ = '4.Doi' THEN 4
WHEN ser_typ = '5.DoubleFly' THEN 5
ELSE 6
END;
2025-02-07 分类(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'
end as ser_typ,
count(trx_amt) trx_cnt,
min(trx_time) first_date
from cmb_usr_trx_rcd 
group by 1
order by ser_typ
2025-02-07 分类(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 '其他'
end as ser_typ,
count(trx_amt) trx_cnt,
min(trx_time) first_date
from cmb_usr_trx_rcd 
group by 1
order by ser_typ
2025-02-07 分组与聚合函数(6)想知道渣男有多坏,疯狂使用GroupBy 
select usr_id,
mch_nm,
sum(trx_amt) trx_amt,
count(trx_amt) trx_cnt,
min(trx_time) first_time
from cmb_usr_trx_rcd 
where usr_id=5201314520
and trx_amt>=288
group by usr_id,mch_nm
order by trx_cnt desc
2025-02-07 分组与聚合函数(6)想知道渣男有多坏,疯狂使用GroupBy 
select usr_id,
mch_nm,
sum(trx_amt) trx_amt,
count(trx_amt) trx_cnt,
min(trx_time) first_time
from cmb_usr_trx_rcd 
where usr_id=5201314520
and trx_amt>=288
group by usr_id,mch_nm
2025-02-07 分组与聚合函数(5)想知道何时成瘾,用Max Or Min? 
SELECT usr_id, MIN(trx_time) AS first_time, mch_nm
FROM cmb_usr_trx_rcd
WHERE mch_nm = '红玫瑰按摩保健休闲'
AND usr_id = 5201314520
GROUP BY usr_id
2025-02-07 分组与聚合函数(5)想知道何时成瘾,用Max Or Min? 
SELECT usr_id, MIN(trx_time) AS first_time, mch_nm
FROM cmb_usr_trx_rcd
WHERE mch_nm = '红玫瑰按摩保健休闲'
AND usr_id = 5201314520
GROUP BY usr_id, mch_nm;