2024-09 思扣SQLintern 中等

上一题的最终输出,前5行如下。

trx_mon last_day day_of_mon trx_amt trx_cnt avg_day_amt avg_day_cnt
2023-01 2023-01-31 31 432.00 2 13.935484 0.0645
2023-02 2023-02-28 28 676.00 2 24.142857 0.0714
2023-03 2023-03-31 31 814.00 2 26.258065 0.0645
2023-05 2023-05-31 31 2064.00 3 66.580645 0.0968
2023-06 2023-06-30 30 888.00 1 29.600000 0.0333

可以发现,2023年4月,渣男的相关消费笔数是0。作为本系列的最后一题,我们要尽可能的完善输出。

1.时间范围限定在渣男在2023年全年、2024年1-6月;

2.对嫖资的界定缩小为如下3个条件,必须同时满足:

  • 商户类目为休闲娱乐或者未被分出
  • 金额为大于288元
  • 交易时间在23:00:00-02:59:59。

3.如果某个月份嫖资消费为0元,也应列出。即输出结果应该为18行,12+6=18个月。

入门-闺蜜捉奸记 时间日期 聚合函数 断点缝合 多表连接 CTE或SubQuery group by left join between and or and max distinct count sum coalesce round / last_day day null

cmb_usr_trx_rcd,支付明细表

usr_id mch_nm trx_time trx_amt
5201314520 肯德基 2023-10-01 12:23:24 49
5211414521 丝芙源网络 2024-03-13 17:23:23 123

cmb_mch_typ,商户分类表

mch_nm mch_typ
肯德基 餐饮
延长壳牌南乐加油站 汽车出行
东海洗浴 休闲娱乐

date_table,日期表,包含2020-01-01至2030-12-31的每一天日期

date_value
2020-01-01
2020-01-02
2020-01-03

 

 成为会员,解锁300道大厂数分SQL真题

ID36 表连接(5)哪些没被分出来,用左用内你来猜  
入门 group by left join and year count sum null 时间日期 聚合函数 多表连接 多列分组 入门-闺蜜捉奸记 思扣SQLintern
ID38 时间日期(2)按月统计日花费,一天都不要浪费  
入门 left join and max year substr in last_day day 时间日期 多表连接 入门-闺蜜捉奸记 思扣SQLintern
ID39 时间日期(3)按月统计日花费,一天都不要浪费  
入门 group by left join and max year count sum substr in / last_day day 时间日期 聚合函数 多表连接 入门-闺蜜捉奸记 思扣SQLintern
ID114 从商品角度统计收藏到购买的转化率  
困难 group by left join inner join distinct count coalesce 多表连接 CTE或SubQuery 购物漏斗分析 小红书
ID216 想念她的味道,工资献给98号  
入门 between and and year day 时间日期 入门-闺蜜捉奸记 思扣SQLintern

MySQL 8.0

00:00