1、题目描述
来源:力扣(LeetCode)
2、解题思路
1# 首先,对连续出现不小于100的记录,进行记录连续次数:参考 185. 部门工资前三高的员工,这次只是用了if函数
(select stadium.*,if(people>=100,@i:=@i+1,@i:=0) as rec1 from stadium,(select @i:=0) a)add_r1,
2# 但是,排序后,想要倒序,然后,按照最大的记录数字,往下取数,太难操作了。
然后我想到了一个,技巧:再倒序排序,然后相加
,这里新建一个子表:
elect id,if(people>=100,@j:=@j+1,@j:=0) as rec2 from stadium,(select @j:=0) b order by id desc
这里我把信息都显示出来,容易看:
3# 最后,rec1+rec2 as jude
,只要jude>=4
的就是了
4# 这一题出现率很高,顺便链接其他解法:
直接3表联查
使用group_concat()
3、提交记录
select id,visit_date ,people
from(
select add_r1.*,rec1+rec2 as jude
from
(select stadium.*,if(people>=100,@i:=@i+1,@i:=0) as rec1
from stadium,(select @i:=0) a)add_r1,
(select id,if(people>=100,@j:=@j+1,@j:=0) as rec2
from stadium,(select @j:=0) b
order by id desc)add_r2
where add_r1.id=add_r2.id)add_jude
where jude>=4
437ms