g0601_0700.s0601_human_traffic_of_stadium.script.sql Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-java Show documentation
Show all versions of leetcode-in-java Show documentation
Java-based LeetCode algorithm problem solutions, regularly updated
# Write your MySQL query statement below
# #Hard #Database
select id, visit_date, people
from
(select
id, visit_date, people,
lead(people, 1) over ( order by id) as 1_next,
lead(people, 2) over ( order by id) as 2_next,
lag(people, 1) over ( order by id) as 1_prev,
lag(people, 2) over ( order by id) as 2_prev
from Stadium
) a
where (people >= 100) and
(
(1_next >= 100 and 2_next >=100) or
(1_prev >= 100 and 2_prev >=100) or
(1_prev >= 100 and 1_next >=100)
)