origin link: https://leetcode.com/problems/human-traffic-of-stadium/description/ the ideal pseudo code I want is
select id from Stadium where people >= 100 into @tmp;
select * from Stadium
where id in tmp and (
(id + 1 in tmp and id + 2 in tmp) or
(id + 1 in tmp and id - 1 in tmp) or
(id - 1 in tmp and id - 2 in tmp)
)
order by visit_date;
what I tried is as follow, but that is too stubborn:
select * from Stadium
where id in (select id from Stadium where people >= 100) and (
(id + 1 in (select id from Stadium where people >= 100) and id + 2 in (select id from Stadium where people >= 100)) or
(id + 1 in (select id from Stadium where people >= 100) and id - 1 in (select id from Stadium where people >= 100)) or
(id - 1 in (select id from Stadium where people >= 100) and id - 2 in (select id from Stadium where people >= 100))
)
order by visit_date;