SQL in leetcode-601. Human Traff

2019-07-14  本文已影响0人  迷糊的小竹笋

最简单的思路为三表连接,连接关系则为日期或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
上一篇 下一篇

猜你喜欢

热点阅读