排名

用户解题统计

过去一年提交了

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

收藏

评论笔记

评论日期 题目名称 评论内容 站长评论
2025-06-11 给商品打四类标签(列) 
u1s1 需求处是不是没表达准确
看输出示例呢?

提交记录

提交日期 题目名称 提交代码
2025-08-07 条件过滤(2)半夜活动有猫腻,Hour函数给给力 
select * 
from cmb_usr_trx_rcd 
where
date(trx_time)between'2024-09-01'and'2024-09-30'
and hour(trx_time)between 1 and 5
and usr_id='5201314520'
2025-07-04 只买iPhone的用户 
select user_id
from apple_pchs_rcd
group by user_id
having sum(case when product_type != 'iphone' then 1 else 0 end) =0
order by 1
2025-07-04 至少两门科目大于等于110分的学生 
select * 
from subject_score
where
(chinese>=110 and math >= 110)
or
(chinese>=110 and english >= 110)
or
(english >= 110 and math >= 110)
order by student_id
2025-07-03 抖音面试真题(5)新用户的T+1月留存 
WITH monthly_unique_logins AS (
    SELECT
        usr_id,
        DATE_FORMAT(login_time, '%Y-%m-01') AS login_month
    FROM
        user_login_log
    WHERE
        login_time >= '2024-01-01' AND login_time < '2025-01-01'
    GROUP BY
        usr_id,
        DATE_FORMAT(login_time, '%Y-%m-01')
),
new_users AS (
    SELECT
        usr_id,
        MIN(login_month) AS first_login_month
    FROM
        monthly_unique_logins
    GROUP BY
        usr_id
),
next_month_logins AS (
    SELECT
        nu.usr_id,
        nu.first_login_month AS current_month,
        mul.login_month AS next_month
    FROM
        new_users nu
    LEFT JOIN
        monthly_unique_logins mul
    ON
        nu.usr_id = mul.usr_id AND
        mul.login_month = DATE_ADD(nu.first_login_month, INTERVAL 1 MONTH)
)
SELECT
    current_month,
    ROUND(COUNT(DISTINCT CASE WHEN next_month IS NOT NULL THEN usr_id END) * 100.0 / COUNT(DISTINCT usr_id), 2) AS t_plus_1_month_retention_rate
FROM
    next_month_logins
WHERE
    current_month >= '2024-01-01' AND current_month < '2025-01-01'
GROUP BY
    current_month
ORDER BY
    current_month;
2025-07-03 1989年12月13日出生的女歌手 
select * 
from singer_info 
where birth_date ='1989-12-13'
2025-07-03 找出所有港台歌手 
select * 
from singer_info 
where type2='港台'
order by 
    1
2025-07-03 找出所有港台歌手 
select * 
from singer_info 
where type2='港台' AND type3='个人'
2025-07-03 找出所有港台乐队 
select * 
from singer_info
where type2='港台' and type3='乐队'
order by singer_id
2025-07-03 找出所有港台乐队 
select * 
from singer_info
where type2='港台'
order by singer_id
2025-07-03 能组成直角三角形的线段 
SELECT *
FROM numbers_for_fun
WHERE 
  CASE 
    WHEN ABS(a) >= ABS(b) AND ABS(a) >= ABS(c) THEN POW(ABS(a), 2) = POW(ABS(b), 2) + POW(ABS(c), 2)
    WHEN ABS(b) >= ABS(a) AND ABS(b) >= ABS(c) THEN POW(ABS(b), 2) = POW(ABS(a), 2) + POW(ABS(c), 2)
    ELSE POW(ABS(c), 2) = POW(ABS(a), 2) + POW(ABS(b), 2)
  END
  and a*b*c<>0
ORDER BY id ASC;
2025-07-03 能组成三角形的线段 
select * 
from numbers_for_fun 
where
a*b*c <> 0
and(
abs(a)+abs(b)>abs(c)
and abs(a)+abs(c)>abs(b)
 and abs(b)+abs(c)>abs(a)
)
 order by id;
2025-07-03 大于J小于K的手牌 
select * 
from hand_permutations 
where card1 between 'J' and'K' and 
card2 between 'J' and 'K'
order by id
;
2025-07-03 语文数学英语至少1门超过100分的同学 
select * 
from subject_score
where chinese >100 or math >100 or english >100 
group by student_id
order by chinese asc
2025-07-03 统计每个作者发布视频的平均互动指数 
WITH VideoInteractions AS (
    SELECT 
        v.author_id,
        SUM(
            w.if_like +
            CASE WHEN w.comment_id IS NOT NULL THEN 1 ELSE 0 END +
            w.if_retweet +
            w.if_fav
        ) AS total_interactions,
        COUNT(DISTINCT v.video_id) AS video_count
    FROM ks_video_inf v
    JOIN ks_video_wat_log w ON v.video_id = w.video_id
    GROUP BY v.author_id
)
SELECT 
    author_id,
    round(total_interactions * 1.0 / video_count,2) AS avg_interaction_index
FROM VideoInteractions
ORDER BY avg_interaction_index DESC;
2025-07-03 计算视频的平均观看完成率 
SELECT 
    v.video_id,
    v.title,
    COALESCE(AVG(TIMESTAMPDIFF(SECOND, w.start_time, w.end_time) / v.duration), 0) AS avg_completion_rate
FROM ks_video_inf v
inner JOIN ks_video_wat_log w ON v.video_id = w.video_id
GROUP BY v.video_id, v.title
ORDER BY avg_completion_rate DESC;
2025-07-03 找出最近一周内发布的竖屏视频 
select video_id,author_id,title
from ks_video_inf
wherescreen_type = 'p' and date(release_time) >= date_sub(curdate(),interval 7 day)
order by release_time desc
2025-07-03 总分超过300分的学生 
with B1 AS (
select student_id,
		chinese+math+english as cnt
from subject_score)
select t1.student_id
from B1 t1
where cnt >= 300
2025-07-02 曝光量最大的商品 
with B1 as (
select t1.cust_uid,t1.if_snd,t1.prd_id,t2.prd_nm,t2.price
from tb_pg_act_rcd t1
left join
tb_prd_map t2
on t1.prd_id=t2.prd_id
)
select prd_id,prd_nm,sum(if_snd)as cnt
from B1
group by prd_id,prd_nm
order by sum(if_snd) desc
limit 1;
2025-07-02 登录天数分布 
with B1 as (select usr_id,
date(login_time) as day
from user_login_log
where login_time >= date_sub(curdate(),interval 180 day)
group by usr_id,date(login_time)
 ),
B2 as(select t1.usr_id,
 		count(distinct t1.day) as cnt
from B1 t1
group by t1.usr_id
 ),
B3 as (select t2.usr_id,
 		sum(case when t2.cnt BETWEEN 1 AND 5 then 1 else 0 end) as days_1_to_5,
sum(case when t2.cnt between 6 and 10 then 1 else 0 end) as days_6_to_10,
sum(case when t2.cnt between 11 and 20 then 1 else 0 end) as days_11_to_20,
SUM(CASE WHEN t2.cnt > 20 THEN 1 ELSE 0 END) AS days_over_20
FROM 
    B2 t2
group by 1)
select 
		sum(t3.days_1_to_5) as days_1_to_5_a,
sum(t3.days_6_to_10) as days_6_to_10_a,
sum(t3.days_11_to_20) as days_11_to_20_a,
sum(t3.days_over_20) as days_over_20_a
from B3 t3
 ;
2025-07-02 登录天数分布 
with B1 as (select usr_id,
date(login_time) as day
from user_login_log
group by usr_id,date(login_time)
 ),
B2 as(select t1.usr_id,
 		count(distinct t1.day) as cnt
from B1 t1
group by t1.usr_id
 ),
B3 as (select t2.usr_id,
 		sum(case when t2.cnt <= 5 then 1 else 0 end) as days_1_to_5,
sum(case when t2.cnt between 6 and 10 then 1 else 0 end) as days_6_to_10,
sum(case when t2.cnt between 11 and 20 then 1 else 0 end) as days_11_to_20,
SUM(CASE WHEN t2.cnt > 20 THEN 1 ELSE 0 END) AS days_over_20
FROM 
    B2 t2
group by 1)
select 
		sum(t3.days_1_to_5) as days_1_to_5_a,
sum(t3.days_6_to_10) as days_6_to_10_a,
sum(t3.days_11_to_20) as days_11_to_20_a,
sum(t3.days_over_20) as days_over_20_a
from B3 t3
 ;