排名

用户解题统计

过去一年提交了

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

收藏

收藏日期 题目名称 解决状态
2026-03-15 7月之后再也没活跃过的用户  已解决

评论笔记

评论日期 题目名称 评论内容 站长评论
2026-03-15 分组与聚合函数(6)想知道渣男有多坏,疯狂使用GroupBy 
找出渣男(usr_id=5201314520)在288元(含)以上的所有交易(不限时间),然后看他第一次去这个商户是什么时候,顺便把他在这个商户的交易次数、总消费金额也列举出来。
存在歧义,可以理解为288元以上交易中第一笔和该商户发生交易的时间;或发生过288元以上交易商户中,第一次和该商户发生交易的时间
参考答案是第一种理解
啥也没说

提交记录

提交日期 题目名称 提交代码
2026-03-15 分组与聚合函数(6)想知道渣男有多坏,疯狂使用GroupBy 
select usr_id,mch_nm,sum(trx_amt)trx_amt,count(usr_id) trx_cnt,min(trx_time) first_time
from cmb_usr_trx_rcd 
where usr_id='5201314520' 
and mch_nm in (
select distinct mch_nm from cmb_usr_trx_rcd where trx_amt>288 and usr_id='5201314520'
)
group by usr_id,mch_nm
order by count(usr_id) desc
2026-03-15 分组与聚合函数(6)想知道渣男有多坏,疯狂使用GroupBy 
select usr_id,mch_nm,min(trx_time),sum(trx_amt),count(usr_id)
from cmb_usr_trx_rcd 
where usr_id='5201314520' 
and mch_nm in (
select distinct mch_nm from cmb_usr_trx_rcd where trx_amt>288 and usr_id='5201314520'
)
group by usr_id,mch_nm
order by count(usr_id) desc
2026-03-15 7月之后再也没活跃过的用户 
select count(distinct usr_id) incative_user_countincative_user_count from (
select year(login_time),month(login_time),usr_id,count(1)
from user_login_log
where concat(year(login_time),month(login_time))<='202407'
and usr_id not in (select usr_id
from user_login_log
where (year(login_time)='2024' and month(login_time)>'7')
 		or year(login_time)>'2024'
group by year(login_time),month(login_time),usr_id
having count(1)>=10
)
group by year(login_time),month(login_time),usr_id
having count(1)>=10
)t
2026-03-15 7月之后再也没活跃过的用户 
select count(distinct usr_id) from (
select year(login_time),month(login_time),usr_id,count(1)
from user_login_log
where concat(year(login_time),month(login_time))<='202407'
and usr_id not in (select usr_id
from user_login_log
where (year(login_time)='2024' and month(login_time)>'7')
 		or year(login_time)>'2024'
group by year(login_time),month(login_time),usr_id
having count(1)>10
)
group by year(login_time),month(login_time),usr_id
having count(1)>10
)t
2026-03-15 7月之后再也没活跃过的用户 
select year(login_time),month(login_time),usr_id,count(1)
from user_login_log
where year(login_time)='2024' and month(login_time)='7'
and usr_id not in (select usr_id
from user_login_log
where (year(login_time)='2024' and month(login_time)>'7')
 		or year(login_time)>'2024'
group by year(login_time),month(login_time),usr_id
having count(1)>10
)
group by year(login_time),month(login_time),usr_id
having count(1)>10
2026-03-15 10月1日后再也没活跃过的用户 
select count(distinct usr_id) as inactive_user_count from user_login_log where cast(login_time as date)<=date'2024-10-01'
and usr_id not in (select distinct usr_id from user_login_log where cast(login_time as date)>date'2024-10-01')
2026-03-15 10月1日后再也没活跃过的用户 
select 
    count(distinct usr_id) as inactive_user_count
from 
    user_login_log
where 
    date(login_time) <= '2024-10-01'
    and not exists (
        select 1
        from user_login_log as log2
        where log2.usr_id = user_login_log.usr_id
          and date(log2.login_time) > '2024-10-01'
    );
2026-03-15 10月1日后再也没活跃过的用户 
select count(1) as inactive_user_count
from(
	select usr_id, max(login_time)
	from user_login_log
	group by 1
	having max(login_time) <= '2024-10-01'
) tmp
2026-03-15 10月1日后再也没活跃过的用户 
select count(distinct usr_id) as inactive_user_count from user_login_log where login_time<=date'2024-10-01'
and usr_id not in (select distinct usr_id from user_login_log where login_time >date'2024-10-01')
2026-03-15 10月1日后再也没活跃过的用户 
select count(distinct usr_id) from user_login_log where login_time<=date'2024-10-01'
and usr_id not in (select usr_id from user_login_log where login_time >date'2024-10-01')
2026-02-28 购买人数最多的商品类目 
select gd_typ,count(1)
from xhs_pchs_rcd a
left join gd_inf b
on a.mch_id=b.gd_id
group by gd_typ
order by count(1) desc
limit 1
2026-02-28 购买人数最多的商品类目 
select gd_nm,count(1)
from xhs_pchs_rcd a
left join gd_inf b
on a.mch_id=b.gd_id
group by mch_id,gd_nm
order by count(1) desc
limit 1
2026-02-28 被收藏次数最多的商品 
SELECT 
    gd.gd_id, 
    gd.gd_nm, 
    COUNT(fav.fav_trq) AS fav_count
FROM 
    xhs_fav_rcd fav
JOIN 
    gd_inf gd ON fav.mch_id = gd.gd_id
GROUP BY 
    gd.gd_id, gd.gd_nm
ORDER BY 
    fav_count DESC
LIMIT 1;
2026-02-28 被收藏次数最多的商品 
select mch_id,count(1)
from xhs_fav_rcd
group by mch_id
order by count(1) desc limit 1