select job,DATE_FORMAT(date, '%Y-%m') as mon,sum(num) as cnt from resume_info where date >'2025-01-01' and date <'2025-12-31' group by job,mon order by mon desc, cnt desc ;
那么我们借鉴这个写出2026年的:
select job,DATE_FORMAT(date, '%Y-%m') as mon,sum(num) as cnt from resume_info where date >'2026-01-01' and date <'2026-12-31' group by job,mon连接这2个表,然后job相等,并且月份相等,月份相等我们可以使用right函数,这个函数是取右边几个字符,这里取出右边2个字符,相等,最后写出:
select first_year.job,first_year.mon as first_year_mon,first_year.cnt as first_year_cnt,second_year.mon as second_year_mon,second_year.cnt as second_year_cnt from (select job,DATE_FORMAT(date, '%Y-%m') as mon,sum(num) as cnt from resume_info where date >'2025-01-01' and date <'2025-12-31' group by job,mon) first_year join (select job,DATE_FORMAT(date, '%Y-%m') as mon,sum(num) as cnt from resume_info where date >'2026-01-01' and date <'2026-12-31' group by job,mon) second_year on first_year.job=second_year.job and right(first_year.mon,2)=right(second_year.mon,2) order by first_year.mon desc, first_year.job desc ;