排名

用户解题统计

过去一年提交了

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

错题集 数据思维刷题中答错的题目

模块 知识点 题目 你的答案 正确答案 操作
暂无错题,继续保持!

收藏

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

评论笔记

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

提交记录

提交日期 题目名称 提交代码
2026-11-26 时间日期(3)按月统计日花费,一天都不要浪费 
select
	date_format(trx_time, '%Y-%m') as trx_mon,
last_day(max(trx_time)) as last_day,
day(last_day(max(trx_time))) as days_of_mon,
sum(trx_amt) as trx_amt,
count(1) as trx_cnt,
sum(trx_amt) / day(last_day(max(trx_time))) as avg_day_amt,
count(1) / day(last_day(max(trx_time))) as avg_day_cnt
from cmb_usr_trx_rcd a 
left join cmb_mch_typ b on a.mch_nm = b.mch_nm
where usr_id = '5201314520'
and year(trx_time) in (2023, 2024)
and b.mch_typ = '休闲娱乐'
group by
	date_format(trx_time, '%Y-%m')
order by trx_mon
;
2026-11-26 时间日期(2)按月统计日花费,一天都不要浪费 
select
	distinct date_format(trx_time, '%Y-%m') as trx_mon,
last_day(trx_time) as last_day,
day(last_day(trx_time)) as days_of_mon
from cmb_usr_trx_rcd a 
left join cmb_mch_typ b on a.mch_nm = b.mch_nm
where usr_id = '5201314520'
and year(trx_time) in (2023, 2024)
and b.mch_typ = '休闲娱乐'
order by trx_mon;
2026-11-26 时间日期(1)按月统计日花费,一天都不要浪费 
select
	distinct date_format(trx_time, '%Y-%m') as trx_mon,
last_day(trx_time) as last_day
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and date(trx_time) between '2023-1-1' and '2024-12-31'
order by trx_mon;
2026-11-26 表连接(5)哪些没被分出来,用左用内你来猜 
select
	b.mch_typ,
a.mch_nm,
count(1) as trx_cnt,
sum(a.trx_amt) as trx_amt
from cmb_usr_trx_rcd a
left join cmb_mch_typ b on a.mch_nm = b.mch_nm
where a.usr_id = '5201314520'
and year(a.trx_time) = 2024
and b.mch_typ is null
group by b.mch_typ, a.mch_nm
order by trx_cnt desc;
2026-11-26 表连接(4)渣男把钱花在哪儿,维表可以来帮忙 
select
	b.mch_typ,
count(1) as trx_cnt,
sum(a.trx_amt) as trx_amt
from cmb_usr_trx_rcd a
left join cmb_mch_typ b on a.mch_nm = b.mch_nm
where a.usr_id = '5201314520'
and year(a.trx_time) = 2024
group by b.mch_typ
order by trx_cnt desc;
2026-11-26 表连接(3)一直使用一张表,现在开始两张表 
select 
	mch_typ,
count(1) as total_mch,
count(distinct mch_nm) as unique_mch_cnt
from cmb_mch_typ
group by mch_typ
order by count(1) desc;
2026-11-26 小结(2)越花越多是死罪,按月统计Substr 
select
	date_format(trx_time, '%Y-%m') as trx_mon,
count(1) as trx_cnt,
sum(trx_amt) as trx_amt
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and date(trx_time) between '2022-11-1' and '2024-12-31'
and (
	(mod(truncate(trx_amt, 0), 100) in (88, 98) and trx_amt > 200 and hour(trx_time) in (23, 0, 1, 2))
or (mch_nm rlike '足疗|保健|按摩|养生|SPA')
)
group by trx_mon
order by trx_mon asc;
2026-11-26 小结(1)大数据早就能扫黄,找足证据不慌张 
select
	case
	when (mod(floor(trx_amt), 100) in (88, 98) and trx_amt > 200)
and (hour(trx_time) in (23, 0 ,1, 2, 3))
then 'illegal'
else 'other'
end as type,
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 type
order by mch_cnt desc;
2026-11-26 财源广进:开除摸鱼的员工 
WITH punch_days AS (
SELECT employee_id,
 TIMESTAMPDIFF(MINUTE, MIN(punch_time), MAX(punch_time)) AS work_minutes
FROM attendance
WHERE YEAR(punch_time) = 2025
GROUP BY employee_id, TO_DAYS(punch_time)
HAVING COUNT(*) >= 2
),
attendance_means AS (
SELECT employee_id,
 CAST(SUM(work_minutes + 0e0) AS DECIMAL(18, 8)) / COUNT(*) AS minutes_per_day
FROM punch_days
GROUP BY employee_id
),
walk_days AS (
SELECT ac.employee_id, COUNT(*) AS swipes
FROM access_control AS ac
WHERE YEAR(ac.timestamp) = 2025
AND HOUR(ac.timestamp) IN (9, 10, 11, 14, 15, 16, 17)
GROUP BY ac.employee_id, TO_DAYS(ac.timestamp)
),
walk_scores AS (
SELECT employee_id,
 CASE WHEN COUNT(*) > 70 AND COUNT(CASE WHEN swipes > 3 THEN 1 END) > 25 THEN 3
WHEN COUNT(*) > 60 THEN 1
ELSE 0 END AS points
FROM walk_days
GROUP BY employee_id
),
flybook AS (
SELECT SQL_BIG_RESULT employee_id,
 SUM(daily_interaction) AS interactions, COUNT(daily_interaction) AS interaction_days,
 SUM(daily_messages)AS messages, COUNT(daily_messages)AS message_days,
 SUM(daily_documents) AS documents,COUNT(daily_documents) AS document_days
FROM flybook_stats
WHERE stat_date >= '20250131'
GROUP BY employee_id
),
company_flybook AS (
SELECT SUM(interactions) AS interactions, SUM(interaction_days) AS interaction_days,
 SUM(messages) AS messages, SUM(message_days) AS message_days,
 SUM(documents)AS documents,SUM(document_days)AS document_days
FROM flybook
),
scored AS (
SELECT e.id AS employee_id,
 CASE WHEN COALESCE(a.minutes_per_day, 0) = 0 THEN 1
WHEN a.minutes_per_day < (SELECT AVG(minutes_per_day) FROM attendance_means) THEN 1
ELSE 0 END AS attendance_points,
 e.salary * (DATEDIFF('2026-03-06', e.hire_date) + 365) AS pay_numerator,
 COALESCE(w.points, 0) AS walk_points,
 IF(COALESCE(f.interactions, 0) * c.interaction_days <
COALESCE(NULLIF(f.interaction_days, 0), 1) * c.interactions, 1, 0) AS low_interactions,
 IF(COALESCE(f.messages, 0) * c.message_days <
COALESCE(NULLIF(f.message_days, 0), 1) * c.messages, 1, 0) AS low_messages,
 IF(COALESCE(f.documents, 0) * c.document_days <
COALESCE(NULLIF(f.document_days, 0), 1) * c.documents, 1, 0) AS low_documents
FROM employees AS e
LEFT JOIN attendance_means AS a ON a.employee_id = e.id
LEFT JOIN walk_scores AS w ON w.employee_id = e.id
LEFT JOIN flybook AS f ON f.employee_id = e.id
CROSS JOIN company_flybook AS c
)
SELECT employee_id,
 attendance_points + walk_points +
 CASE WHEN pay_numerator < 10 * 12 * 365 THEN 3
WHEN pay_numerator < 20 * 12 * 365 THEN 2
WHEN pay_numerator < 30 * 12 * 365 THEN 1
ELSE 0 END +
 CASE (low_interactions + low_messages + low_documents)
WHEN 3 THEN 3 WHEN 2 THEN 1 ELSE 0 END AS score
FROM scored;
2026-11-25 表连接(2)渣男去过我对象没去过,那就用LeftJoin 
select
a.mch_nm as asshole_tried,
a.trx_cnt as trx_cnt,
b.mch_nm as darling_tried
from
(
select mch_nm, count(1) as trx_cnt
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and year(trx_time) in (2023, 2024)
group by mch_nm
having count(trx_cnt) >= 20
) a
left join
(
select distinct mch_nm
from cmb_usr_trx_rcd
where usr_id = '5211314521'
and year(trx_time) in (2023, 2024)
) b
on a.mch_nm = b.mch_nm
order by trx_cnt desc;
2026-11-25 表连接(2)渣男去过我对象没去过,那就用LeftJoin 
select
a.mch_nm as asshole_tried,
a.trx_cnt as trx_cnt,
b.mch_nm as darling_tried
from
(
select mch_nm, count(1) as trx_cnt
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and year(trx_time) between 2023 and 2024
group by mch_nm
) a
left join
(
select distinct mch_nm
from cmb_usr_trx_rcd
where usr_id = '5211314521'
and year(trx_time) between 2023 and 2024
) b
on a.mch_nm = b.mch_nm
order by a.trx_cnt desc;
2026-11-25 表连接(2)渣男去过我对象没去过,那就用LeftJoin 
select
a.mch_nm as asshole_tried,
a.trx_cnt,
b.mch_nm as darling_tried
from
(
select mch_nm, count(1) as trx_cnt
from cmb_usr_trx_rcd
where usr_id = '5201314520'
and year(trx_time) between 2023 and 2024
group by mch_nm
) a
left join
(
select distinct mch_nm
from cmb_usr_trx_rcd
where usr_id = '5211314521'
and year(trx_time) between 2023 and 2024
) b
on a.mch_nm = b.mch_nm
order by a.trx_cnt desc;
2026-11-25 表连接(1)你们难道都去过?那就试试用InnerJoin 
with zhanan as (
select mch_nm
from cmb_usr_trx_rcd
where year(trx_time) = 2024
and usr_id = '5201314520'
),
npy as (
select mch_nm
from cmb_usr_trx_rcd
where year(trx_time) = 2024
and usr_id = '5211314521'
)
select distinct a.mch_nm
from zhanan a
inner join npy b on a.mch_nm = b.mch_nm;
2026-11-25 子查询(1)玩的最嗨那天在做甚?要用Where子查询 
select *
from cmb_usr_trx_rcd
where trx_amt in (
select max(trx_amt)
from cmb_usr_trx_rcd
where usr_id='5201314520'
and year(trx_time) = 2024
);
2026-11-25 字符串与通配符(2)好多关键词做规则,可以使用rlike 
select
	case when mch_nm like '%按摩保健休闲%' then '按摩保健休闲'
		when 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 mch_nm rlike '按摩|保健|休闲|养生|SPA|会所'
group by reg_rules
order by mch_cnt desc;
2026-11-25 字符串与通配符(1)名称里面有特服,可以使用通配符 
SELECT 
			COUNT(DISTINCT mch_nm) AS mch_cnt
FROM cmb_usr_trx_rcd
WHERE mch_nm LIKE '%红玫瑰按摩保健休闲%';
2026-11-25 分类(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 mch_nm = '红玫瑰按摩保健休闲'
AND usr_id = '5201314520'
GROUP BY ser_typ
ORDER BY ser_typ;
2026-11-25 分类(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
GROUP BY ser_typ
ORDER BY ser_typ;
2026-11-25 分类(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(trx_time) as first_date
FROM cmb_usr_trx_rcd
GROUP BY ser_typ
ORDER BY ser_typ;
2026-11-25 分组与聚合函数(6)想知道渣男有多坏,疯狂使用GroupBy 
select
		usr_id,
mch_nm,
sum(trx_amt) as trx_amt,
count(*) as trx_cnt,
min(trx_time) as 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;