- 题目总体不难,但有一点折腾了很久,就是使用date_format函数之后,时间戳格式改变为文本格式了,后面就不能使用year函数,
- 对于文本截取有很多函数都可以,当格式比较整齐使用left和right函数最方便, 有时候需要使用regexp_substr之类的函数功能更加强大
with base as
(select job ,DATE_FORMAT(date,"%Y-%m") as mon,sum(num) as cnt
from resume_info
group by job,DATE_FORMAT(date,"%Y-%m"))
select b1.job,b1.mon ,b1.cnt,
b2.mon,b2.cnt
from base b1 left join base b2
on b1.job=b2.job and left(b1.mon,4)+1=left(b2.mon,4)
and Right(LEFT(b1.mon,7),2)=Right(LEFT(b2.mon,7),2)
having left(b1.mon,4)=2025
order by b1.mon desc,b1.job desc