SQL in leetcode-601. Human Traffic of Stadium

最简单的思路为三表连接,连接关系则为日期或id之间的关系。

select distinct s1.* from stadium s1, stadium s2, stadium s3
where ((s1.id = s2.id - 1 and s1.id = s3.id - 2)
or (s1.id = s2.id - 1 and s1.id = s3.id + 1) 
or (s1.id = s2.id + 1 and s1.id = s3.id + 2)) 
and (s1.people >= 100 and s2.people >= 100 and s3.people >= 100) 
order by id asc

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