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

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

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;
全部评论

相关推荐

点赞 评论 收藏
分享
用户64975461947315:这不很正常吗,2个月开实习证明,这个薪资也还算合理,深圳Java好多150不包吃不包住呢,而且也提前和你说了没有转正机会,现在贼多牛马公司骗你说毕业转正,你辛辛苦苦干了半年拿到毕业证,后面和你说没hc了😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务