select a.job, a.mon as first_year_mon, a.cnt as first_year_cnt,
b.mon as second_year_mon, b.cnt as second_year_cnt
from
(select job, left(date,7) as mon, sum(num) as cnt
from resume_info
where year(date) = 2025
group by job, mon
order by mon desc, cnt desc) as a
left outer join
(select job, left(date,7) as mon, sum(num) as cnt
from resume_info
where year(date) = 2026
group by job, mon
order by mon desc, cnt desc) as b
on a.job = b.job
and month(concat(a.mon,'-01')) =
month(concat(b.mon,'-01'))
order by first_year_mon desc, job desc;
这道题最绝的地方在于倒数第二步,突然来个回马枪,将mon再重新组装成为“年-月-日”格式,这样就可以使用year()
,month()
格式了。