排名

用户解题统计

过去一年提交了

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

收藏

收藏日期 题目名称 解决状态
2025-03-10 基于共同兴趣爱好的餐厅推荐(6)-好基友(5)  已解决
2025-03-10 多云天气天数  已解决
2025-01-26 小丑竟是我自己  未解决
2025-01-25 海王:1小时发3个红包  已解决
2025-01-20 德州扑克起手牌-同花两高张  未解决
2025-01-20 通勤、午休、临睡个时间段活跃人数分布  未解决

评论笔记

评论日期 题目名称 评论内容 站长评论
2025-02-03 餐厅的客单价增长趋势 
//自己记录用
**考察coalesce用法,计算同环比场景,被做对比的数据为0时,取0
**考察nullif用法,计算比例,同环比,上期或同期为0, 做分母,避免被除数为0,nullif判断被除数是否为0,为0则取null
**考察round用法,计算同环比,保留小数,比值先乘以100,再四舍五入保留小数部位
**考察开窗函数
啥也没说
2025-01-26 小丑竟是我自己 
比例是 (1-A/B)*100 吗
是的~,你再试下应该能通过了
2025-01-26 小丑竟是我自己 
知识点:
rcv_datetime != '1900-01-01 00:00:00'  1900-01-01代表没有列值的记录,此处用作判断没有被接收的红包的记录
啥也没说
2025-01-21 德州扑克起手牌-同花两高张 
select count(1) as cnt,
			(select count(1) from hand_permutations) as ttl_cnt,
            round(count(1)/(select count(1) from hand_permutations),4) as p
from 
(select distinct card1,card2
from hand_permutations 
where right(card1,1)=right(card2,1)
and (left(card1,length(card1)-1) between 'A' and 'K') 
and (left(card2,length(card2)-1) between 'A' and 'K')) t1
啥也没说
2025-01-21 文科潜力股 
SELECT *
 FROM scores 
 where ((subject ='历史' and score>90)
 or (subject ='地理' and score>90)
 or (subject ='政治' and score>90))
 and exam_date='2024-06-30'
 order by score desc,student_id,subject
啥也没说
2025-01-21 找出所有以酒店为起点或终点的类别组合的最热门路线 
注意关联条件的列名,以及题解是求最热门的路线组合,需要再次分区(分组)排名
啥也没说
2025-01-21 至少两门科目大于等于110分的学生 
select *
 from subject_score
 where (chinese>=110 and math>=110)
 or (chinese>=110 and english>=110)
 or (math>=110 and english>=110)
 order by student_id

select a1.*
from subject_score a1
inner join 
(select student_id,
			(c1+m1+e1) as tll
from
 (select student_id,
 			case when chinese>=110 then 1 else 0 end as c1,
            case when math>=110 then 1 else 0 end as m1,
            case when english>=110 then 1 else 0 end as e1
 from subject_score) t 
) a2 
on a1.student_id=a2.student_id
where a2.tll>=2


select *
from subject_score
where if(chinese>=110,1,0)+if(math>=110,1,0)+if(english>=110,1,0) >=2
啥也没说
2025-01-21 渣男腰子可真行,端午中秋干不停 
多个where筛选条件,注意and和or的运算优先级,括号的使用
啥也没说
2025-01-21 分组与聚合函数(5)五花八门的项目,其实都有固定套路(2) 
计算客单数和消费人数,人均客单数的区别
啥也没说
2025-01-21 条件过滤(3)Hour函数很给力,组合条件要仔细 
注意输出排序
啥也没说
2025-01-21 通勤、午休、临睡个时间段活跃人数分布 
使用变量?
啥也没说
2025-01-21 通勤、午休、临睡个时间段活跃人数分布 
select 
(select count(distinct usr_id)
from user_login_log
where 
 ((substr(login_time,12,8) between '07:30:00' and '09:30:00')
or (substr(login_time,12,8) between '18:30:00' and '20:30:00'))
and (substr(login_time,1,10) between date_add(current_date()-day(current_date())+1,interval -1 month) and date_add(last_day(current_date()),interval -1 month))) as commute,
(select count(distinct usr_id)
from user_login_log
where (substr(login_time,12,8) between '11:30:00' and '14:00:00')
and (substr(login_time,1,10) between date_add(current_date()-day(current_date())+1,interval -1 month) and date_add(last_day(current_date()),interval -1 month))) as lunch_break,
(select count(distinct usr_id)
from user_login_log
where (substr(login_time,12,8) between '22:30:00' and '01:00:00')
and (substr(login_time,1,10) between date_add(current_date()-day(current_date())+1,interval -1 month) and date_add(last_day(current_date()),interval -1 month))) as bedtime
啥也没说
2025-01-21 性别已知的听歌用户 
在听歌记录表取值,关联用户信息表
啥也没说
2025-01-20 各地区包含“中国”或“中”字开头的公司数量及比例 
和上题例不同,公司名称条件不用去除以“中国”结尾的,且包含“中”字的公司不需要限定以中字开头。
注意order by之后不接聚合函数,order by和聚合函数有不同的语义和执行顺序。

输出结果proportiton的小数位为4位,结果未通过。
啥也没说
2025-01-20 每个行业最早上市的公司 
只考虑那些名称以“中国”开头或包含“中”字的公司:
1. 以“中国”开头的公司,需要同时剔除以“中国”结尾的公司
2. 包含“中”字的公司,题解为以“中”字开头的公司,不是名称出现“中”字的公司
这里有一些误解
啥也没说
2025-01-19 条件过滤(1)异地男友有异常,数分闺蜜来帮忙 
使用date_format函数可以吗
可以的。实际业务中,如果用于过滤,怎么方便怎么来;如果是用于输出,要严格遵守输出要求,因为后续就要导入到pythonexcel啥的,会有格式要求,那就推荐date_format。😁

提交记录

提交日期 题目名称 提交代码
2025-03-11 招建银行信用卡中心客户挽留-电商平台分类 
select mch_nm as merchant_name,
		case 
when mch_nm regexp '拼多多|上海寻梦信息技术' then '拼多多'
 		when mch_nm regexp '京东|北京京东世纪贸易' then '京东'
 		when mch_nm regexp '淘宝|天猫|浙江淘宝网络|浙江天猫网络' then '淘系'
 		when mch_nm regexp '抖音|北京抖音信息服务' then '抖音'
 		when mch_nm regexp '小红书|行吟信息科技' then '小红书'
else '其他'
end as platform
from 
(select mch_nm,count(*)
from ccb_trx_rcd
group by mch_nm
order by 2 desc) a 
order by 2 desc
2025-03-10 基于共同兴趣爱好的餐厅推荐(6)-好基友(5) 
select cust_uid,
		cust_uid_1
from
(
		select a.cust_uid,
 			b.cust_uid as cust_uid_1,
 			a.mch_nm
			from 
					(select distinct cust_uid,mch_nm from mt_trx_rcd1 where cust_uid='MT10000') a 
					inner join 
						(select distinct cust_uid,mch_nm from mt_trx_rcd1 where cust_uid<>'MT10000') b 
				on a.mch_nm=b.mch_nm
				group by 1,2,3) c 
group by 1,2
having count(mch_nm)>=14
2025-03-10 基于共同兴趣爱好的餐厅推荐(5)-好基友(3) 
select a.cust_uid,b.cust_uid as cust_uid_1
from 
(select distinct cust_uid,mch_nm from mt_trx_rcd1 where cust_uid='MT10000') a 
left join 
(select cust_uid from mt_trx_rcd1 
 group by cust_uid 
 having count(distinct case when mch_nm in ('庄家界(千灯店)','黄记烘培宫廷桃酥王','品众素心素食餐厅') then mch_nm else null end)=3
) b
on a.cust_uid<>b.cust_uid
group by 1,2
order by 2
2025-03-10 基于共同兴趣爱好的餐厅推荐(5)-好基友(3) 
select a.cust_uid,b.cust_uid as cust_uid_1
from 
(select distinct cust_uid,mch_nm from mt_trx_rcd1 where cust_uid='MT10000') a 
left join 
(select cust_uid from mt_trx_rcd1 
 group by cust_uid 
 having count(distinct case when mch_nm in ('庄家界(千灯店)','黄记烘培宫廷桃酥王','品众素心素食餐厅') then mch_nm else null end)=3
) b
on a.cust_uid<>b.cust_uid
order by 2
2025-03-10 基于共同兴趣爱好的餐厅推荐(4)-好基友(2) 
select a.cust_uid,
		c.cust_uid as cust_uid_1 
from 
(select distinct cust_uid,mch_nm from mt_trx_rcd1 where cust_uid='MT10000') a
left join 
(select b1.cust_uid
  from 
  (select distinct cust_uid, mch_nm from mt_trx_rcd1 where mch_nm='庄家界(千灯店)' ) b1
inner join 
  (select distinct cust_uid, mch_nm from mt_trx_rcd1 where mch_nm='黄记烘培宫廷桃酥王' ) b2
on b1.cust_uid = b2.cust_uid) c 
on a.cust_uid<>c.cust_uid 
group by 1,2
order by 2
2025-03-10 基于共同兴趣爱好的餐厅推荐(3)-好基友(1) 
select t1.cust_uid,
			t2.cust_uid_1,
t1.mch_nm
from 
		(select distinct cust_uid, 
 				mch_nm 
			from mt_trx_rcd1
			where cust_uid='MT10000'
			order by mch_nm) t1 
	inner join 
		(select distinct cust_uid as cust_uid_1,
		 			mch_nm
			from mt_trx_rcd1
			where mch_nm='兰州李晓明拉面馆'
			order by 1) t2
on t1.mch_nm=t2.mch_nm and t1.cust_uid<>t2.cust_uid_1
order by 2
2025-03-10 基于共同兴趣爱好的餐厅推荐(3)-好基友(1) 
select t1.cust_uid,
			t2.cust_uid_1,
t1.mch_nm
from 
		(select distinct cust_uid, 
 				mch_nm 
			from mt_trx_rcd1
			where cust_uid='MT10000'
			order by mch_nm) t1 
	inner join 
		(select distinct cust_uid as cust_uid_1,
		 			mch_nm
			from mt_trx_rcd1
			where mch_nm='兰州李晓明拉面馆'
			order by 1) t2
on t1.mch_nm=t2.mch_nm
order by 2
2025-03-10 基于共同兴趣爱好的餐厅推荐(3)-好基友(1) 
select t1.cust_uid,
			t2.cust_uid_1,
t1.mch_nm
from 
		(select distinct cust_uid, 
 				mch_nm 
			from mt_trx_rcd1
			where cust_uid='MT10000'
			order by mch_nm) t1 
	right join 
		(select distinct cust_uid as cust_uid_1,
		 			mch_nm
			from mt_trx_rcd1
			where mch_nm='兰州李晓明拉面馆'
			order by 1) t2
on t1.mch_nm=t2.mch_nm
order by 2
2025-03-10 基于共同兴趣爱好的餐厅推荐(2)-还有谁吃过 
select distinct cust_uid,
		mch_nm
from mt_trx_rcd1
where mch_nm='兰州李晓明拉面馆'
order by 1
2025-03-10 基于共同兴趣爱好的餐厅推荐(1)-我吃过啥 
select distinct cust_uid,
			mch_nm
from mt_trx_rcd1
where cust_uid='MT10000'
order by 2
2025-03-10 北京有雪的日子 
select dt,
			tmp_h,
tmp_l,
con 
from weather_rcd_china
where city='beijing'
and con like '%雪%'
2025-03-10 北京有雪的日子 
select dt,
			tmp_h,
tmp_l,
wnd 
from weather_rcd_china
where city='beijing'
and con like '%雪%'
2025-03-10 一线城市历年平均气温 
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-03-10 一线城市历年平均气温 
select year(dt) as Y,
 			round(sum(case when city='beijing' then cast(tmp_h as decimal(10,5)) else 0 end)/
 count(case when city='beijing' then cast(tmp_h as decimal(10,5)) else null end),2)as '北京',
 round(sum(case when city='shanghai' then cast(tmp_h as decimal(10,5)) else 0 end)/
 count(case when city='shanghai' then cast(tmp_h as decimal(10,5)) else null end),2)as '上海',
 round(sum(case when city='shenzhen' then cast(tmp_h as decimal(10,5)) else 0 end)/
 count(case when city='shenzhen' then cast(tmp_h as decimal(10,5)) else null end),2)as '深圳',
 round(sum(case when city='guangzhou' then cast(tmp_h as decimal(10,5)) else 0 end)/
 count(case when city='guangzhou' then cast(tmp_h as decimal(10,5)) else null end),2)as '广州'
 from weather_rcd_china
 where (year(dt) between 2011 and 2022)
 and city in ('beijing','shanghai','shenzhen','guangzhou')
 group by 1
 order by 1
2025-03-10 冬季下雪天数 
select city,
			sum(case when month(dt) in (12,1,2) and con like '%雪%' then 1 else 0 end) as snowy_days
from weather_rcd_china
group by city 
order by 2 desc
2025-03-10 多云天气天数 
select t1.city,
 		count(t1.dt) as cloudy_days,
concat(round((count(t1.dt)/t2.ttl)*100,2),'%') as p 
 from weather_rcd_china t1 
 		inner join 
		 	(select city,
 		count(dt) as ttl
 			from weather_rcd_china
 			where year(dt)=2021
 			group by city) t2 
 		on t1.city=t2.city
 where year(dt)=2021
 and con like '%多云%'
 group by city 
 order by 2 desc
2025-03-10 城市平均最高气温 
select city,
			cast(avg(tmp_h) as decimal(10,2)) as avg_tmp_h
 from weather_rcd_china
 where year(dt) = 2021
 group by city 
 order by 2 desc
2025-02-03 深圳气温异常年份 
select dt as year,
		 cast(avg_tmp_h as decimal(10,2)) as avg_tmp_h,
 significant_change
from 
(select dt,
		 avg_tmp_h,
 lag(avg_tmp_h,1) over(),
 avg_tmp_h-lag(avg_tmp_h,1) over(),
 case when abs(avg_tmp_h-lag(avg_tmp_h,1) over(order by dt))>=1 then 'Yes' else 'No' end as significant_change
from 
	(select year(dt) as dt,
 		 		avg(replace(tmp_h,'℃','')+0) as avg_tmp_h
	from weather_rcd_china
 where city = 'shenzhen'
	group by 1
	order by 1) t1) t2
2025-02-03 深圳气温异常年份 
select dt as year,
		 round(avg_tmp_h,2) as avg_tmp_h,
 significant_change
from 
(select dt,
		 avg_tmp_h,
 lag(avg_tmp_h,1) over(),
 avg_tmp_h-lag(avg_tmp_h,1) over(),
 case when abs(avg_tmp_h-lag(avg_tmp_h,1) over(order by dt))>=1 then 'Yes' else 'No' end as significant_change
from 
	(select year(dt) as dt,
 		 		avg(replace(tmp_h,'℃','')+0) as avg_tmp_h
	from weather_rcd_china
 where city = 'shenzhen'
	group by 1
	order by 1) t1) t2
2025-02-03 深圳气温异常年份 
select dt as year,
		 round(avg_tmp_h,2) as avg_tmp_h,
 significant_change
from 
(select dt,
		 avg_tmp_h,
 lag(avg_tmp_h,1) over(),
 avg_tmp_h-lag(avg_tmp_h,1) over(),
 case when avg_tmp_h-lag(avg_tmp_h,1) over()>=1 then 'Yes' else 'No' end as significant_change
from 
	(select year(dt) as dt,
 		 		avg(tmp_h) as avg_tmp_h
	from weather_rcd_china
 where city = 'shenzhen'
	group by 1
	order by 1) t1) t2