使用MySQL解法,采用多表连接,但不灵活(比如至少连续100记录),效率低。
select distinct c.id,c.visit_date,c.people from stadium c
inner join
(select a.id aid , b.id bid from stadium a inner join stadium b on (a.id-1=b.id or a.id+1=b.id or a.id-2=b.id or a.id+2=b.id) and a.people>99 and b.people>99) temp
on
(
(temp.aid-temp.bid=1 and (c.id+1=temp.bid or c.id-1=temp.aid))
or
(c.id-1=temp.bid and c.id+1=temp.aid)
or
(temp.bid-temp.aid=1 and (c.id+1=temp.aid or c.id-1=temp.bid))
or
(c.id-1=temp.aid and c.id+1=temp.bid)
)
and temp.aid
and c.people>99
order by c.id;