601. Human Traffic of Stadium

四层嵌套,I‘m’ fine,fuck you!

总之思想就是先把不到100的T了,然后重新给一个全表排序序号,你会发现,相邻的日期,id(或者日期)减去新排序rownum的值是相同的,然后相同的count超过3个的就是我们想要的值,总之属于暴力解题,幸亏性能过关了,so,就这样了


# Write your MySQL query statement below
set @rownum1:=0;
set @rownum2:=0;
select temp1.id,temp1.date,temp1.people
from (select count(*) as row_counts,diffnum
from (select t.*,t.id-t.row_num as diffnum
from (select a.*,
   @rownum1:=@rownum1+1 as row_num
  from (select * from stadium  where people>=100) a) t)s
group by diffnum) temp2
join
(select t.*,t.id-t.row_num as diffnum
 from (select a.*,
   @rownum2:=@rownum2+1 as row_num
     from (select * from stadium  where people>=100) a) t) temp1
on (temp1.diffnum=temp2.diffnum)
where temp2.row_counts>=3
order by temp1.date

你可能感兴趣的:(601. Human Traffic of Stadium)