排名

用户解题统计

过去一年提交了

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

收藏

收藏日期 题目名称 解决状态
2024-12-30 条件过滤(1)异地男友有异常,数分闺蜜来帮忙  已解决

评论笔记

评论日期 题目名称 评论内容 站长评论
2025-02-24 大结局(😊)渣男9月爽翻天,罪证送他去西天 
菜鸡做了很久想不出来,参考答案的思路后才做出来,记录一下:

/*全量日期表*/
with full_day_list as (
			select
				date_value
			from 
				date_table
			where
				year(date_value) = 2024
                and month(date_value) = 9
			order by
				date_value
),

/*计算基本type次数*/
time_trx_type as (
			select
				date(trx_time) as dt,
                count(1) as fvck_cnt,
                sum(case when trx_amt = 288 then 1 else 0 end) as  WithHand,
                sum(case when trx_amt = 388 then 1 else 0 end) as  WithBalls,
                sum(case when trx_amt = 588 then 1 else 0 end) as  BlowJobbie,
                sum(case when trx_amt = 888 then 1 else 0 end) as  Doi,
                sum(case when trx_amt = 1288 then 1 else 0 end) as  DoubleFly
			from 
				cmb_usr_trx_rcd
			where
				usr_id = 5201314520
                and mch_nm rlike ('按摩|保健|休闲|会所')
                and year(trx_time) = 2024 
                and  month(trx_time) = 9
			group by 
				date(trx_time) 
			order by 
				dt
),

/*ohya特殊分类次数的日期*/
oyha_dt as (
			select 
				date(trx_time) as dt
			from(
					select
						*,
						lag(trx_time,1) over(partition by usr_id order by trx_time) as last_time,
                        lag(trx_amt,1) over(partition by usr_id order by trx_time) as last_amt
					from
						cmb_usr_trx_rcd
					where
						usr_id = 5201314520
						and mch_nm rlike ('按摩|保健|休闲|会所')
						and year(trx_time) = 2024 
						and  month(trx_time) = 9
				) as a
			where
				trx_amt = 888
				and last_amt = 1288
				and date(trx_time) = date(last_time)
)

/*合并日期,整合ohya列数据*/
select
	a.date_value,
    coalesce(b.fvck_cnt,0) as fvck_cnt,
	coalesce(b.WithHand,0) as WithHand,
	coalesce(b.WithBalls,0) as WithBalls,
	coalesce(b.BlowJobbie,0) as BlowJobbie,
	coalesce(b.Doi,0) as Doi,
	coalesce(b.DoubleFly,0) as DoubleFly,
    case when c.dt is not null then 1 else 0 end as ohya
from
	full_day_list as a
left join
	time_trx_type as b on a.date_value = b.dt
left join
	oyha_dt as c on a.date_value = c.dt
order by 
	a.date_value
    
    
    
/*整体解题思路:
	① 先得到完整的日期列表
    ② 再得到基础type的次数,每种分类按列统计 
    ③ 再单独计算出ohya的统计列
			(难点:先Doi后Double怎么实现;
					-- 求出下次消费金额 和 下次消费时间
                    -- 本次消费金额=888,下次消费金额=1288
                    -- 且要求2次消费日期为同一天)
	④ 最后将①左联②左连③,注意处理null值转换
*/
啥也没说

提交记录

提交日期 题目名称 提交代码
2025-03-14 基于共同兴趣爱好的餐厅推荐(6)-好基友(5) 
select a.cust_uid, c.cust_uid from 
(
select cust_uid, mch_nm from mt_trx_rcd1 where cust_uid='MT10000' group by cust_uid, mch_nm) a 
left join
(
select cust_uid, mch_nm from mt_trx_rcd1 group by cust_uid, mch_nm
  )c
on a.cust_uid <> c.cust_uid and a.mch_nm = c.mch_nm
group by a.cust_uid, c.cust_uid
2025-03-14 基于共同兴趣爱好的餐厅推荐(3)-好基友(1) 
select 
   'MT10000' as  cust_uid,cust_uid as cust_uid_1 ,mch_nm 
from 
    mt_trx_rcd1 
where 
    mch_nm='兰州李晓明拉面馆'and cust_uid != 'MT10000'
group by
    cust_uid, mch_nm 
order by 2
2025-03-14 基于共同兴趣爱好的餐厅推荐(3)-好基友(1) 
select 
   'MT10000' as  cust_uid,cust_uid as cust_uid_1 ,mch_nm 
from 
    mt_trx_rcd1 
where 
    mch_nm='兰州李晓明拉面馆'and mch_nm != 'MT10000'
group by
    cust_uid, mch_nm 
order by 2
2025-03-14 基于共同兴趣爱好的餐厅推荐(3)-好基友(1) 
select 
   'MT10000' as  cust_uid,cust_uid as cust_uid_1 ,mch_nm 
from 
    mt_trx_rcd1 
where 
    mch_nm='兰州李晓明拉面馆'
group by
    cust_uid, mch_nm 
order by 2
2025-03-10 小结(1)大数据早就能扫黄,找足证据不慌张 
select
    case
        when
            (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)
        then 'illegal'
        else 'other'
    end as trx_typ,
    count(1) as trx_cnt,
    sum(trx_amt) as trx_amt,
    count(distinct mch_nm) as mch_cnt
from
    cmb_usr_trx_rcd
where
    usr_id = '5201314520'
group by
    1
order by
    trx_cnt desc;
2025-03-10 小结(1)大数据早就能扫黄,找足证据不慌张 
select
	case
	when (truncate(trx_amt, 0) like '%88' or truncate(trx_amt, 0) like '%98')
 and hour(trx_time) in (23, 00, 01, 02, 03)
then 'illegal'
else 'other'
end as trx_typ,
count(1) trx_cnt,
sum(trx_amt) trx_amt,
count(distinct mch_nm) mch_nm
from
	cmb_usr_trx_rcd
where
	usr_id = '5201314520'
and trx_amt > 200
group by
	1
order by
	1 desc;
2025-03-09 字符串与通配符(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-03-09 字符串与通配符(1)名称里面有特服,可以使用通配符 
select 
	count(distinct mch_nm) mch_cnt
from 
	cmb_usr_trx_rcd 
where
	mch_nm like '%按摩保健休闲%'
2025-03-09 分类(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) trx_cnt,
min(date(trx_time)) first_date
from
	cmb_usr_trx_rcd
where
	mch_nm = '红玫瑰按摩保健休闲'
	and usr_id = '5201314520'
group by
	1
order by
	1
2025-03-09 分类(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) trx_cnt,
min(date(trx_time)) first_date
from
	cmb_usr_trx_rcd
where
	mch_nm = '红玫瑰按摩保健休闲'
	and usr_id = '5201314520'
group by
	1
order by
	1
2025-03-09 分组与聚合函数(6)想知道渣男有多坏,疯狂使用GroupBy 
select
	usr_id,
mch_nm,
sum(trx_amt) trx_amt,
count(1) trx_cnt,
min(trx_time) first_time
from
	cmb_usr_trx_rcd
where
	usr_id = '5201314520'
and	trx_amt >= 288
group by
	1,2
order by
	trx_cnt desc
2025-03-09 分组与聚合函数(5)想知道何时成瘾,用Max Or Min? 
select
	usr_id,
min(trx_time) first_time,
mch_nm
from
	cmb_usr_trx_rcd
where
	usr_id = '5201314520'
and mch_nm = '红玫瑰按摩保健休闲'
group by
	1,3
2025-03-09 分组与聚合函数(5)想知道何时成瘾,用Max Or Min? 
select
	usr_id,
mch_nm,
min(trx_time) first_time
from
	cmb_usr_trx_rcd
where
	usr_id = '5201314520'
and mch_nm = '红玫瑰按摩保健休闲'
group by
	1,2
2025-03-09 分组与聚合函数(5)五花八门的项目,其实都有固定套路(2) 
select
	trx_amt,
count(1) total_trx_cnt,
count(distinct usr_id) unique_usr_cnt,
round(count(1)/count(distinct usr_id), 4) avg_trx_per_user
from
	cmb_usr_trx_rcd
where
	mch_nm = '红玫瑰按摩保健休闲'
and date(trx_time) between '2023-01-01' and '2024-06-30'
group by
	trx_amt
order by
	avg_trx_per_user desc
limit 5
2025-03-09 分组与聚合函数(3)五花八门的项目,其实都有固定套路(1) 
select 
	trx_amt,
count(1) trx_cnt
from 
	cmb_usr_trx_rcd
where
	mch_nm = '红玫瑰按摩保健休闲'
and	date(trx_time) between '2024-01-01' and '2024-07-31'
group by
	trx_amt
order by
	trx_cnt desc
limit 5
2025-03-09 分组与聚合函数(2)擦边营收怎么样,聚合函数可看出 
select
	date(trx_time) trx_date,
max(trx_amt) max_trx_amt,
min(trx_amt) min_trx_amt,
avg(trx_amt) avg_trx_amt,
sum(trx_amt) total_trx_amt
from
	cmb_usr_trx_rcd
where
	mch_nm = '红玫瑰按摩保健休闲'
and year(trx_time) = 2024
and month(trx_time) = 9
group by
	1
order by
	1
2025-03-09 分组与聚合函数(1)Money全都花在哪,GroupBy来查一查 
select
	mch_nm,
sum(trx_amt) sum_trx_amt
from
	cmb_usr_trx_rcd
where
	usr_id = '5201314520'
and	year(trx_time) = 2024
group by
	mch_nm
order by
	sum_trx_amt desc
2025-03-09 条件过滤(3)Hour函数很给力,组合条件要仔细 
select
	*
from
	cmb_usr_trx_rcd
where
	usr_id = '5201314520'
and date(trx_time) between '2024-09-01'and '2024-09-30'
and Hour(trx_time)in (22,23,0,1,2,3,4,5)
order by
	trx_time
2025-03-09 条件过滤(3)Hour函数很给力,组合条件要仔细 
select
	*
from
	cmb_usr_trx_rcd
where
	usr_id = '5201314520'
and date(trx_time) between '2024-09-01'and '2024-09-30'
and Hour(trx_time)in (22,23,0,1,2,3,4,5,6)
order by
	trx_time
2025-03-09 条件过滤(2)半夜活动有猫腻,Hour函数给给力 
select
	*
from
	cmb_usr_trx_rcd
where
	usr_id = '5201314520'
and date(trx_time) between '2024-09-01'and '2024-09-30'
and hour(trx_time) between '01:00:00'and '05:00:00'
order by
	trx_time