题解 | #实习广场投递简历分析(三)#
实习广场投递简历分析(三)
http://www.nowcoder.com/practice/83f84aa5c32b4cf5a75558d02dd7743c
分别求出2025年和2026年的job,日期和数量, 最主要的就是如何将两个表相连接.相同job不同年相同月份,job和date不是唯一且无法作为主键使用.所以连接条件需要进行各个设置: 首先将每个表的job相连接, 然后利用right()函数分别取出日期中的月份进行相连接
select a.job,first_year_mon,first_year_cnt,
second_year_mon,second_year_cnt
from
(SELECT job,date_format(date,'%Y-%m') as first_year_mon,
sum(num)as first_year_cnt
from resume_info
where year(date)=2025
group by job,first_year_mon)a
join
(select job,date_format(date,'%Y-%m') as second_year_mon,
sum(num) as second_year_cnt
from resume_info
where year(date)=2026
group by job,second_year_mon)b
on a.job=b.job
and right(first_year_mon,2)=right(second_year_mon,2)
order by first_year_mon desc,a.job desc;
right函数
right('ABCDEF',2)
---->EF
left函数
left('ABCDEF',2)
---->AB
right函数和left函数类似于sql中的提取字符串函数 substr(字符串,start,length)