美文网首页
SQL in leetcode-601. Human Traff

SQL in leetcode-601. Human Traff

作者: 迷糊的小竹笋 | 来源:发表于2019-07-14 21:47 被阅读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

相关文章

网友评论

      本文标题:SQL in leetcode-601. Human Traff

      本文链接:https://www.haomeiwen.com/subject/tlzikctx.html