排名

用户解题统计

过去一年提交了

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

收藏

收藏日期 题目名称 解决状态
2025-05-01 窗口函数(3)越来越喜欢召妓,窗口函数用累计(1)  未解决
2025-05-01 时间日期(4)阶段综合-按月统计日花费,一天都不要浪费  未解决
2025-04-30 时间日期(3)按月统计日花费,一天都不要浪费  已解决
2025-04-29 时间日期(2)按月统计日花费,一天都不要浪费  已解决
2025-04-29 表连接(5)哪些没被分出来,用左用内你来猜  已解决
2025-04-29 表连接(4)渣男把钱花在哪儿,维表可以来帮忙  已解决
2025-04-29 基于共同兴趣爱好的餐厅推荐(6)-好基友(5)  已解决
2025-04-29 基于共同兴趣爱好的餐厅推荐(4)-好基友(2)  已解决
2025-04-28 基于共同兴趣爱好的餐厅推荐(3)-好基友(1)  已解决
2025-04-28 从未被领取的优惠券  已解决
2025-04-28 用户听歌完成情况  已解决
2025-04-27 最受欢迎歌手  已解决
2025-04-27 MJ最受欢迎的歌曲  未解决
2025-04-27 周杰伦的最受欢迎的专辑  已解决
2025-04-26 统计每个作者发布视频的平均互动指数  已解决
2025-04-24 各行业第一家上市公司  未解决
2025-04-22 横屏与竖屏视频的完播率(按AI配音和字幕分类)  已解决
2025-04-21 频道重合指数  未解决
2025-04-20 多类别观看指数计算  未解决
2025-04-20 对各品牌购买贡献度最高的三个关键词  未解决
2025-04-19 统计每个城市各状态的单量(行转列)  已解决
2025-04-19 统计每个城市各状态的单量  已解决
2025-04-18 计算每个城市的有效订单完成率  已解决
2025-04-17 从商品角度统计收藏到购买的转化率  已解决
2025-04-12 找出所有类别组合的最热门路线  已解决
2025-04-12 找出所有以酒店为起点或终点的类别组合的最热门路线  已解决
2025-04-12 找出所有以酒店为起点的类别组合的最热门路线  已解决
2025-04-11 找出酒店-餐饮的最热门路线  已解决
2025-04-09 查询所有起点和终点都属于餐饮类别的行程  已解决
2025-04-09 只被收藏未被购买的商品  未解决
2025-04-09 购买人数最多的商品类目  已解决
2025-04-04 文科潜力股  已解决
2025-04-03 小结-从不缺考的学生  已解决
2025-04-03 HAVING-语数英优异的学生  已解决
2025-04-03 HAVING-执教教师超过3人的科目  已解决
2025-04-03 CASE WHEN-男女学生的数量  已解决
2025-04-03 聚合函数-比较两位同学的数学成绩  已解决
2025-04-03 GROUP BY-年龄最大学生的出生日期  已解决
2025-04-03 条件过滤-没有职称的老教师  已解决
2025-04-03 字符串函数-查找任教5个班级的所有教师  已解决
2025-04-03 NULL的知识点  已解决
2025-04-02 数学成绩分段统计(3)  已解决
2025-03-30 数学成绩分段统计(2)  已解决
2025-03-27 各班第一名  已解决
2025-03-27 平均分最高的班级  已解决
2025-03-26 化学老师的教学成果  已解决
2025-03-22 优异物理成绩的分布  已解决
2025-03-21 经过第四象限的所有函数  未解决
2025-03-21 不经过第二象限的所有函数  已解决
2025-03-21 基于共同兴趣爱好的餐厅推荐(1)-我吃过啥  已解决
2025-03-21 A和K之间的手牌(1)  已解决
2025-03-20 大于J小于K的手牌  已解决
2025-03-20 语文数学英语至少1门超过100分的同学  已解决
2025-03-20 21世纪上市的银行  已解决
2025-03-19 查询播放量为0的歌手及其专辑  已解决
2025-03-19 用户听歌习惯的时间分布  已解决
2025-03-16 海王发红包  已解决
2025-03-16 接收红包金额绿茶榜  未解决
2025-03-16 至少两门科目大于等于110分的学生  已解决
2025-03-16 渣男腰子可真行,端午中秋干不停  已解决
2025-03-16 小结-行转列,展开学生成绩(1)  已解决
2025-03-12 HAVING-每次成绩都不低于80分的学生  已解决
2025-03-12 CASE WHEN-老中青教师数量  已解决
2025-03-12 条件过滤-查找2009年出生的女学生  已解决
2025-03-12 数学成绩分段统计(1)  已解决
2025-03-12 S1年级物理成绩前10名(1)  已解决
2025-03-12 S1年级物理成绩前10名(2)  已解决
2025-03-06 登录天数分布  未解决
2025-03-06 通勤、午休、临睡个时间段活跃人数分布  已解决
2025-03-04 上月活跃用户数  已解决
2025-03-03 一线城市历年平均气温  已解决
2025-03-03 多云天气天数  已解决
2025-03-03 德州扑克起手牌-最强起手牌KK+  已解决
2025-03-03 抖音面试真题(1)T+1日留存率  未解决

评论笔记

评论日期 题目名称 评论内容 站长评论
2025-04-21 各班第一名 
这题容易在最后一步忘记限定考试日期
啥也没说
2025-04-21 优异物理成绩的分布 
这一题好像比较容易忽略教师的科目还是要限制的
啥也没说
2025-04-20 对各品牌购买贡献度最高的三个关键词 
为什么参考答案不关联点击记录表?如果没有不关联点击记录表,应该就没有办法限定用户是按照“搜索——点击——购买”的流程消费的吧?万一用户在同一个session当中既搜索了关键词又从搜索结果以外的地方点击页面购买商品呢?
手动点赞!你这才算是深入理解了漏斗。漏斗需要人来定义的,你的是灰常严格的定义👍
2025-04-18 计算每天的有效订单完成率 
参考答案末尾 ORDER BY completion_rate DESC; 
但是输出示例似乎是按照日期排序的
啥也没说
2025-04-18 计算每个城市的有效订单完成率 
用一次group by 可以同时计算出订单总数和有效订单数,count(*) count(case when……)
啥也没说
2025-04-18 从商品角度统计收藏到购买的转化率 
使用两表联合,条件是商品id相等和用户ID相等,但是在where语句里过滤收藏时间早于购买时间却产生了奇怪的结果:收藏用户和购买用户数量相等了。代码如下:
with purchase_cnt as (
  select
  	f.mch_id,
  	count(distinct f.cust_uid) as fav_user_cnt,
  	count(distinct p.cust_uid) as pcs_user_cnt
  from
  	xhs_fav_rcd f 
  left join 
  	xhs_pchs_rcd p on p.mch_id = f.mch_id and p.cust_uid = f.cust_uid 
  where
  	p.pchs_tm > f.fav_tm
  group by
  	f.mch_id
)

select 
	mch_id,
    fav_user_cnt,
    pcs_user_cnt,
    round(100 * cast(pcs_user_cnt as float) / fav_user_cnt, 2) as convert_rate
from 
	purchase_cnt
group by
	mch_id,
    fav_user_cnt,
    pcs_user_cnt
order by
	convert_rate desc;
后来把 p.pchs_tm > f.fav_tm 写在了on里面 on p.mch_id = f.mch_id and p.cust_uid = f.cust_uid and p.pchs_tm > f.fav_tm,结果就都对了。为什么会这样?
啥也没说
2025-04-12 找出所有类别组合的最热门路线 
为什么这里用danse_rank?
啥也没说
2025-04-12 找出所有类别组合的最热门路线 
group by 的参数有很多时,group by 是怎样分组的呢?我们想让它以start_ctg和end_ctg分组,但是r.start_loc和r.end_loc不会干扰吗?
啥也没说
2025-04-10 查询所有起点和终点都属于餐饮类别的行程 
起点是餐饮、终点是餐饮两个子查询,同时在两个集合中的地点:id相同,且时间相同
with start_catering as (
  select
  	r.cust_uid,
  	r.start_loc,
  	r.end_loc,
  	r.start_tm,
  	r.car_cls
  from
  	didi_sht_rcd r 
  inner join
  	loc_nm_ctg l on l.loc_nm = r.start_loc
  where
  	l.loc_ctg = '餐饮'
),
end_catering as (
  select
  	r.cust_uid,
  	r.start_loc,
  	r.end_loc,
  	r.start_tm,
  	r.car_cls
  from
  	didi_sht_rcd r 
  inner join 
  	loc_nm_ctg l on l.loc_nm = r.end_loc
  where
  	l.loc_ctg = '餐饮'
)
select 
	s.* 
from 
	start_catering s 
inner join 
	end_catering e on s.cust_uid = e.cust_uid and s.start_tm = e.start_tm
order by
	s.start_tm asc
;
啥也没说
2025-04-09 只被收藏未被购买的商品 
这一题如果用DISTINCT怎么做呢?
啥也没说
2025-04-05 化学老师的教学成果 
select 
	t.name,
    count(distinct s.student_id) as total_stu,
    count(distinct (case when sc.score < 60 then s.student_id else null end)) as unpass_stu,
    count(distinct case when sc.score < 60 then s.student_id else null end) / count(distinct s.student_id) as up_rate
from students s 
inner join 
	teachers t on t.class_code like concat('%', s.class_code, '%')
inner join
	scores sc on s.student_id = sc.student_id
where
	t.subject = '化学'
group by
	t.name
;

这样写有问题吗?未及格学生人数和正确结果有1-3的误差,不知为什么。
仔细阅读你的链接条件,化学老师所带班级的学生成绩,你这样是把所有科目成绩都算进去了。要么在case when条件里加一个sc.subject='化学',要么在where 条件里过滤出化学成绩。
2025-04-03 小结-从不缺考的学生 
select 
	student_id
from scores 
group by
	student_id
having
	count(exam_date) = count(score)
order by
	student_id;
啥也没说
2025-04-03 字符串函数-查找任教3个班级的所有教师 
select 
	name,
    subject,
    class_code
from 
	teachers 
where 
	class_code like 'C___C___C___'
order by
	name asc;
啥也没说
2025-04-03 字符串函数-查找任教5个班级的所有教师 
select 
	name,
    subject,
    class_code
from 
	teachers 
where
	class_code like 'C___C___C___C___C___'
order by
	name asc;
 
啥也没说
2025-04-02 数学成绩分段统计(3) 
with score_ranges as (
  select 
  	st.class_code,
  	count(*) as class_total, 
	sum(case when sc.score >= 110 then 1 else 0 end) as excellent,
    sum(case when sc.score between 90 and 109 then 1 else 0 end) as good,
    sum(case when sc.score between 60 and 89 then 1 else 0 end) as pass,
    sum(case when sc.score < 60 then 1 else 0 end) as fail
  from
  	students st
  inner join
  	scores sc on sc.student_id = st.student_id
  where
  	exam_date = '2024-06-30' and sc.subject = '数学'
  group by
  	st.class_code
)
select 
	class_code,
    class_total,
    concat(excellent, ' ,', round(100 * excellent / class_total, 2), '%') as excellent,
    concat(good, ' ,', round(100 * good / class_total, 2), '%') as good,
    concat(pass, ' ,', round(100 * pass / class_total, 2), '%') as pass,
    concat(fail, ' ,', round(100 * fail / class_total, 2), '%') as fail
from score_ranges
group by class_code
order by class_code;
 
啥也没说
2025-04-02 数学成绩分段统计(2) 
with total_levels as (
  select 
  	student_id,
  	(case when score >= 110 then 1 else 0 end) as excellent,
  	(case when score between 90 and 109 then 1 else 0 end) as good,
  	(case when score between 60 and 89 then 1 else 0 end) as pass,
  	(case when score < 60 then 1 else 0 end) as fail
  from scores
  where exam_date = '2024-06-30' and subject = '数学'
)
select 
	s.class_code,
    sum(excellent) as excellent,
    sum(good) as good,
    sum(pass) as pass,
    sum(fail) as fail
from 
	total_levels as t 
inner join 
	students as s on s.student_id = t.student_id
group by
	s.class_code
order by
	s.class_code;
啥也没说
2025-03-30 数学成绩分段统计(1) 
这题只要scores一个表就行了吧?
case when好像会短路,所以要从大数往小了判断
短路这个词用的好啊。关于短路,你再研究研究,要是我就想从小到大来写,又该怎么办呢?(理论上只需要保证所有条件符合MECE原则,管你怎么写,都能算出来)
2025-03-21 经过第四象限的所有函数 
a=0,b>0时,c是否应该>0才能经过第二象限?
a>0时,是否不需要其他条件曲线都能经过第二象限?
select * 
from numbers_for_fun 
where
	(
      a = 0 and
      (
        (b > 0 and c > 0)
        or 
        (b < 0)
        or 
        (b = 0 and c < 0)
      )
    ) 
    or a > 0
    or (
      a < 0 and 
      (
        (b > 0 and c > 0)
        or 
        (b < 0 and c > b*b/4/a)
      )
    );
只有你在认真刷题。我忘改标题了,是经过第【四】象限的所有函数
2025-03-21 基于共同兴趣爱好的餐厅推荐(1)-我吃过啥 
select 
    distinct cust_uid, 
    mch_nm 
from mt_trx_rcd1 
where cust_uid = 'MT10000'
order by mch_nm;
也可以
是的。
deepseek询问 distinct 和group by哪个效率更高,分别使用什么场景,让自己再多学一点知识
2025-03-21 经过至少两个象限的一元一次函数 
c = 0 直线也可以经过两个象限啊
只要是一元一次函数,他一定经过至少两个象限是不?
2025-03-21 找出与X轴交点大于0的一元一次函数 
select * 
from numbers_for_fun 
where
	a = 0 
    and 
    b <> 0
    -(c/b) > 0
order by id;
直线与x轴的交点:bx+c=0, 那么x=-(c/b)。应该是这样的吧?
 -(c/b) > 0 跟参考答案的条件是一样的哦
2025-03-20 查询播放量为0的歌手及其专辑 
song_info 要用left join,是因为有些歌手或专辑可能没有歌曲在线?我用inner join最终没有结果。所以“播放量为0”包含了“有歌曲在线无播放记录”和“歌手的歌曲不在线因此无从播放”两个子集?
这题考的就是inner join和left join的使用场景。你运行这段代码试试,SELECT 
    s.singer_id,
    s.singer_name,
    a.album_id,
    a.album_name,
    COUNT(l.id) AS play_count
FROM 
    singer_info s
JOIN 
    album_info a ON s.singer_id = a.singer_id
inner JOIN 
    song_info sg ON a.album_id = sg.album_id
inner JOIN 
    listen_rcd l ON sg.song_id = l.song_id
GROUP BY 
    s.singer_id, s.singer_name, a.album_id, a.album_name。
2025-03-16 接收红包金额绿茶榜 
参考答案和输出示例给出的是接收红包的用户的id,但是题设给的要求是发出红包用户id。
而且参考答案里的year(rcv_datetime) != 1900也不知所谓。
啥也没说
2025-03-16 至少两门科目大于等于110分的学生 
sum(
   case
      when chinese >= 110 then 1 
      when math >= 110 then 1
      when english >= 110 then 1
      else 0
   end
) >= 2
这种判断不能按预想的执行,因为case when 短路了,第一个条件执行完后面的就不判断了,所以sum永远不能得到2
啥也没说
2025-03-16 至少两门科目大于等于110分的学生 
sum(
 case 
when
)
啥也没说
2025-03-04 国庆假期后第一天涨幅高于1%的股票 
涨跌幅如果是按照给出的公式计算的话,应该是小于1的小数吧,不是百分比吧?
啥也没说
2025-03-03 滴滴面试真题(2)打车订单呼叫应答时间 
有很多订单有应答后面又被取消了,所以应答时间和是否取消订单没关系啊
啥也没说
2025-02-26 分类(1)姿势太多很过分,分类要用CaseWhen 
提问:SQL语句的执行顺序不是from-where-group by-having-select吗?为什么在select里声明的ser_typ可以用在group by里呢?执行group by的时候SQL怎么知道有ser_typ?
还有一个隐藏的动作 execute(执行),select你可以理解为渲染、挑选,把执行后的结果捡出来,捡的实际动作就是纯捡,不产生任何新的字段。
2025-02-24 条件过滤(2)半夜活动有猫腻,Hour函数给给力 
对日期使用 between and 不是默认两个边界值都是0点吗?between '2024-09-01' and '2024-09-30'就是2024-09-01 00:00:00到2024-09-30 00:00:00,那么如果表里有9月30号0点以后的记录也不会被查询到了?
是的 看第一题 你可以实验一下

提交记录

提交日期 题目名称 提交代码
2025-05-03 时间日期(4)阶段综合-按月统计日花费,一天都不要浪费 
with trx_amt_counting as (
select 
	substr(r.trx_time, 1, 7) as trx_mon,
sum(r.trx_amt) as trx_amt
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.trx_time between '2023-01-01' and '2024-07-01'
and 
r.usr_id = 5201314520
and 
r.trx_amt >= 288 
and 
(t.mch_typ = '休闲娱乐' or t.mch_nm is null)
and 
hour(r.trx_time) in (23, 0, 1, 2)
group by
	trx_mon
)
select
	substr(max(d.date_value), 1, 7) as trx_mon,
case when t.trx_amt is null then '1900-01-01' else last_day(max(d.date_value)) end as last_day,
case when t.trx_amt is null then 0 else dayofmonth(last_day(max(d.date_value))) end as day_of_mon,
coalesce(t.trx_amt, '0') as trx_amt,
count(*) as trx_cnt,
coalesce(round(t.trx_amt / dayofmonth(last_day(max(d.date_value))), 2), 0) as avg_day_amt,
coalesce(round(count(*) / dayofmonth(last_day(max(d.date_value))), 2), 0) as avg_day_cnt
from
	date_table d 
left join
	trx_amt_counting t on t.trx_mon = substr(d.date_value, 1, 7)
group by
	trx_mon,
t.trx_amt
order by
	trx_mon;
2025-05-01 窗口函数(3)越来越喜欢召妓,窗口函数用累计(1) 
select 
	date_format(r.trx_time, '%Y-%m') as trx_mon,
sum(r.trx_amt) as trx_amt
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on r.mch_nm = t.mch_nm
where
	usr_id = 5201314520
and
date_format(r.trx_time, '%Y-%m') between '2023-01' and '2024-12'
and
t.mch_typ = '休闲娱乐'
group by
	trx_mon
order by
	trx_mon;
2025-05-01 时间日期(4)阶段综合-按月统计日花费,一天都不要浪费 
select 
	substr(r.trx_time, 1, 7) as trx_mon,
case when sum(r.trx_amt) = 0 then '1900-01-01' else last_day(max(r.trx_time)) end as last_day,
dayofmonth(last_day(max(r.trx_time))) as day_of_month,
sum(r.trx_amt) as trx_amt,
count(*) as trx_cnt,
round(sum(r.trx_amt) / dayofmonth(last_day(max(r.trx_time))), 2) as avg_day_amt,
round(count(*) / dayofmonth(last_day(max(r.trx_time)))) as avg_day_cnt
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	(t.mch_typ = '休闲娱乐'
or 
 t.mch_typ is null)
and
r.trx_amt > 288
and
hour(r.trx_time) in (23, 0, 1, 2)
and
 	trx_time between '2023-01-01' and '2024-07-01'
group by
	trx_mon
order by
	trx_mon asc
;
2025-04-30 时间日期(3)按月统计日花费,一天都不要浪费 
select
	substr(r.trx_time, 1, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
day(last_day(max(r.trx_time))) as days_of_mon,
sum(r.trx_amt) as trx_amt,
count(*) as trx_cnt,
sum(r.trx_amt) / day(last_day(max(r.trx_time))) as avg_day_amt,
count(r.trx_time) / dayofmonth(last_day(max(r.trx_time))) as avg_day_cnt
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
and 
t.mch_typ = '休闲娱乐'
group by
	trx_mon
order by
	trx_mon asc;
2025-04-30 时间日期(3)按月统计日花费,一天都不要浪费 
select
	substr(r.trx_time, 1, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
day(last_day(max(r.trx_time))) as days_of_mon,
sum(r.trx_amt) as trx_amt,
count(*) as trx_cnt,
sum(r.trx_amt) / count(*) as avg_day_amt,
count(r.trx_time) / dayofmonth(last_day(max(r.trx_time))) as avg_day_cnt
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
and 
t.mch_typ = '休闲娱乐'
group by
	trx_mon
order by
	trx_mon asc;
2025-04-30 时间日期(3)按月统计日花费,一天都不要浪费 
select
	substr(r.trx_time, 1, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
day(last_day(max(r.trx_time))) as days_of_mon,
sum(r.trx_amt) as trx_amt,
count(*) as trx_cnt,
sum(r.trx_amt) / count(r.trx_time) as avg_day_amt,
count(r.trx_time) / dayofmonth(last_day(max(r.trx_time))) as avg_day_cnt
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
and 
t.mch_typ = '休闲娱乐'
group by
	trx_mon
order by
	trx_mon asc;
2025-04-30 时间日期(3)按月统计日花费,一天都不要浪费 
select
	substr(r.trx_time, 1, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
day(last_day(max(r.trx_time))) as days_of_mon,
sum(r.trx_amt) as trx_amt,
count(r.trx_time) as trx_cnt,
sum(r.trx_amt) / count(r.trx_time) as avg_day_amt,
count(r.trx_time) / dayofmonth(last_day(max(r.trx_time))) as avg_day_cnt
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
and 
t.mch_typ = '休闲娱乐'
group by
	trx_mon
order by
	trx_mon asc;
2025-04-30 时间日期(3)按月统计日花费,一天都不要浪费 
select
	substr(r.trx_time, 1, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
dayofmonth(last_day(max(r.trx_time))) as days_of_mon,
sum(r.trx_amt) as trx_amt,
count(r.trx_time) as trx_cnt,
sum(r.trx_amt) / count(r.trx_time) as avg_day_amt,
count(r.trx_time) / dayofmonth(last_day(max(r.trx_time))) as avg_day_cnt
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
and 
t.mch_typ = '休闲娱乐'
group by
	trx_mon
order by
	trx_mon asc;
2025-04-30 时间日期(3)按月统计日花费,一天都不要浪费 
select
	substr(trx_time, 1, 7) as trx_mon,
last_day(max(trx_time)) as last_day,
dayofmonth(last_day(max(trx_time))) as days_of_mon,
sum(trx_amt) as trx_amt,
count(trx_time) as trx_cnt,
sum(trx_amt) / count(trx_time) as avg_day_amt,
count(trx_time) / dayofmonth(last_day(max(trx_time))) as avg_day_cnt
from 
	cmb_usr_trx_rcd 
where
	usr_id = '5201314520'
and
year(trx_time) in (2023, 2024)
group by
	trx_mon
order by
	trx_mon asc;
2025-04-30 时间日期(2)按月统计日花费,一天都不要浪费 
select 
	left(r.trx_time, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
dayofmonth(last_day(max(r.trx_time))) as day_of_mon
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
and 
t.mch_typ = '休闲娱乐'
group by
	trx_mon
order by
	trx_mon asc
;
2025-04-29 时间日期(2)按月统计日花费,一天都不要浪费 
select 
	left(r.trx_time, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
day(last_day(max(r.trx_time))) as day_of_mon
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
and 
t.mch_typ = '休闲娱乐'
group by
	trx_mon
order by
	trx_mon asc
;
2025-04-29 时间日期(2)按月统计日花费,一天都不要浪费 
select 
	substr(r.trx_time, 1, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
day(last_day(max(r.trx_time))) as day_of_mon
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
and 
t.mch_typ = '休闲娱乐'
group by
	trx_mon
order by
	trx_mon asc
;
2025-04-29 时间日期(2)按月统计日花费,一天都不要浪费 
select substr(trx_time,1,7) as trx_mon ,last_day(max(trx_time)) as last_day, day(last_day(max(trx_time)) ) as day_of_mon
from cmb_usr_trx_rcd a
left join cmb_mch_typ m
on a.mch_nm = m.mch_nm
where a.usr_id=5201314520 and year(a.trx_time) in (2023, 2024) and m.mch_typ='休闲娱乐'
group by substr(a.trx_time,1,7)
order by 1 ;
2025-04-29 时间日期(2)按月统计日花费,一天都不要浪费 
select 
	left(r.trx_time, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
day(last_day(max(r.trx_time))) as day_of_mon
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm and t.mch_typ = '休闲娱乐'
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
group by
	trx_mon
order by
	trx_mon asc
;
2025-04-29 时间日期(2)按月统计日花费,一天都不要浪费 
select 
	left(r.trx_time, 7) as trx_mon,
last_day(max(r.trx_time)) as last_day,
dayofmonth(last_day(max(r.trx_time))) as day_of_mon
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm and t.mch_typ = '休闲娱乐'
where
	r.usr_id = '5201314520'
and
year(r.trx_time) in (2023, 2024)
group by
	trx_mon
order by
	trx_mon asc
;
2025-04-29 时间日期(2)按月统计日花费,一天都不要浪费 
select 
	left(trx_time, 7) as trx_mon,
last_day(trx_time) as last_day,
dayofmonth(last_day(trx_time)) as day_of_mon
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm and t.mch_typ = '休闲娱乐'
where
	usr_id = '5201314520'
and
year(trx_time) in (2023, 2024)
order by
	trx_mon asc
;
2025-04-29 时间日期(2)按月统计日花费,一天都不要浪费 
select 
	left(trx_time, 7) as trx_mon,
last_day(trx_time) as last_day,
dayofmonth(trx_time) as day_of_mon
from 
	cmb_usr_trx_rcd r 
left join
	cmb_mch_typ t on t.mch_nm = r.mch_nm and t.mch_typ = '休闲娱乐'
where
	usr_id = '5201314520'
and
year(trx_time) in (2023, 2024)
order by
	trx_mon asc
;
2025-04-29 表连接(5)哪些没被分出来,用左用内你来猜 
select 
	t.mch_typ,
r.mch_nm,
count(r.mch_nm) as trx_cnt,
sum(r.trx_amt) as trx_amt
from 
	cmb_usr_trx_rcd r
left join
	cmb_mch_typ t on r.mch_nm = t.mch_nm
where
	r.usr_id = '5201314520'
and 
left(r.trx_time, 4) = '2024'
group by
	t.mch_typ,
r.mch_nm
having
	t.mch_typ is null
order by
	trx_cnt desc;
2025-04-29 表连接(4)渣男把钱花在哪儿,维表可以来帮忙 
select 
	t.mch_typ,
count(r.mch_nm) as trx_cnt,
sum(r.trx_amt) as trx_amt
from 
	cmb_usr_trx_rcd r 
left join 
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
and 
year(r.trx_time) = 2024
group by
	t.mch_typ
order by
	trx_cnt desc;
2025-04-29 表连接(4)渣男把钱花在哪儿,维表可以来帮忙 
select 
	t.mch_typ,
count(distinct r.mch_nm) as trx_cnt,
sum(r.trx_amt) as trx_amt
from 
	cmb_usr_trx_rcd r 
left join 
	cmb_mch_typ t on t.mch_nm = r.mch_nm
where
	r.usr_id = '5201314520'
group by
	t.mch_typ
order by
	trx_cnt desc;