LC-601 体育馆人流量

问题:

用sql语言查询连续三天人流量超过100的体育馆的信息

思路:

sql语言不是很熟练,这里的方法也很暴力,就是将大于100人流量的体育馆记录全部做连接,然后筛选出id相邻3个的。。

代码:

 1 # Write your MySQL query statement below
 2 
 3 select s1.* 
 4 from stadium as s1, stadium as s2, stadium as s3 
 5 where s1.people >= 100 and s2.people >= 100 and s3.people >= 100 
 6 and (
 7     (s1.id + 1 = s2.id and s1.id + 2 = s3.id) 
 8     or
 9     (s1.id - 1 = s2.id and s1.id + 1 = s3.id) 
10     or
11     (s1.id - 2 = s2.id and s1.id - 1 = s3.id)
12 )
13 group by s1.id;

猜你喜欢

转载自www.cnblogs.com/leo-lzj/p/10327936.html