题解 | #实习广场投递简历分析(三)#

实习广场投递简历分析(三)

http://www.nowcoder.com/practice/83f84aa5c32b4cf5a75558d02dd7743c

select
	t1.job
	,date_format(t1.date,'%Y-%m') as first_year_mon
	,sum(t1.cnt) as first_year_cnt
	,date_format(t2.date,'%Y-%m') as second_year_mon
	,sum(t2.cnt) as second_year_cnt
from 
	(select 
		job
		,date
		,sum(num) as cnt 
	from resume_info 
	group by job,date_format(date,'%Y-%m')) t1 #first_year各月汇总
join
	(select 
		job
		,date
		,sum(num) as cnt 
	from resume_info 
	group by job,date_format(date,'%Y-%m')) t2 #second_year各月汇总
on t1.job = t2.job 
and date_format(t1.date,'%Y-%m') = date_format(date_sub(t2.date,interval 1 year),'%Y-%m')
where year(t1.date) = '2025'
group by t1.job,date_format(t1.date,'%Y-%m')
order by first_year_mon desc,t1.job desc

记录一下解题过程中踩过的坑;

  1. 时间函数参数date要为标准形式; 连接条件最开始写的: date_format(t1.date,'%Y-%m') = date_sub(date_format(t2.date,'%Y-%m'),interval 1 year) 试过之后发现不会报错但会返回空值
  2. 汇总求和时顺序错误; 最初我是按照年份差1、月份相同做连接之后再求和。但这样同一个月份之间的多条数据会形成笛卡尔积,导致计数重复。
全部评论

相关推荐

三题看不懂四题不明白二题无法AC T=int(input()) for _ in range(T): n=int(input()) s=input().split() k,mx=1,1 for i in range(len(s)-1): if len(s[i])<len(s[i+1]): k+=1 elif len(s[i])==len(s[i+1]): if s[i]<=s[i+1]: k+=1 ...
恭喜臭臭猴子:第二题用栈就行。合法的括号直接出栈了,剩下的是不合法的,肯定都得一个一个走。出入栈的过程中得记下进栈的括号的下标。最后栈里剩下的括号如果相邻两个的下标不连续,说明它们中间有一个合法的括号序列被出栈,结果加一
投递拼多多集团-PDD等公司10个岗位 > 拼多多求职进展汇总 笔试
点赞 评论 收藏
分享
03-21 08:46
已编辑
门头沟学院 C++
一个什么都不会的学生:当你有硕士学历的时候HR会说就是比本科生强
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务