题解 | #连续两次作答试卷的最大时间窗#

连续两次作答试卷的最大时间窗

http://www.nowcoder.com/practice/9dcc0eebb8394e79ada1d4d4e979d73c

select
	a.uid,
	days_window,
	round(b.`avg` * a.days_window, 2)avg_exam_cnt
from
	(
	select
		uid, max(days_window)days_window
	from
		(
		select
			uid, datediff((
			select
				start_time
			from
				exam_record
			where
				uid in (
				select
					uid
				from
					exam_record
				where
					year(start_time)= 2021
				group by
					uid
				having
					count(distinct date_format(start_time, '%Y-%m-%d'))>1)
				and r.uid = uid
				and r.start_time < start_time
			order by
				start_time
			limit 1),start_time)+ 1 days_window
		from
			exam_record r
		where
			uid in (
			select
				uid
			from
				exam_record
			where
				year(start_time)= 2021
			group by
				uid
			having
				count(distinct date_format(start_time, '%Y-%m-%d'))>1)
			and year(start_time)= 2021
		order by
			start_time)s
	group by
		uid)a
left join (
	select
		uid, count(date_format(start_time, '%Y-%m-%d'))/(datediff(max(start_time),min(start_time))+1) `avg`
	from
		exam_record
	where
		year(start_time)= 2021
	group by
		uid
	having
		count(distinct date_format(start_time, '%Y-%m-%d'))>1) b on
	a.uid = b.uid
order by
	days_window desc,
	avg_exam_cnt desc;
全部评论

相关推荐

白火同学:1、简历可以浓缩成一页,简历简历先要“简”方便HR快速过滤出有效信息,再要“历”用有效信息突出个人的含金量。 2、教育背景少了入学时间~毕业时间,HR判断不出你是否为应届生。 3、如果你的平台账号效果还不错,可以把账号超链接或者用户名贴到对应位置,一是方便HR知道你是具体做了什么内容的运营,看到账号一目了然,二是口说无凭,账号为证,这更有说服力。
面试被问期望薪资时该如何...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务