标签:span 连续 people class where 要求 state mysq style
X 市建了一个新的体育馆,每日人流量信息被记录在这三列信息中:序号(id)、日期 (date)、 人流量 (people)。
请编写一个查询语句,找出高峰期时段,要求连续三天及以上,并且每天人流量均不少于100。
例如,表 stadium
:
+------+------------+-----------+ | id | date | people | +------+------------+-----------+ | 1 | 2017-01-01 | 10 | | 2 | 2017-01-02 | 109 | | 3 | 2017-01-03 | 150 | | 4 | 2017-01-04 | 99 | | 5 | 2017-01-05 | 145 | | 6 | 2017-01-06 | 1455 | | 7 | 2017-01-07 | 199 | | 8 | 2017-01-08 | 188 | +------+------------+-----------+
对于上面的示例数据,输出为:
+------+------------+-----------+ | id | date | people | +------+------------+-----------+ | 5 | 2017-01-05 | 145 | | 6 | 2017-01-06 | 1455 | | 7 | 2017-01-07 | 199 | | 8 | 2017-01-08 | 188 | +------+------------+-----------+
Note:
每天只有一行记录,日期随着 id 的增加而增加。
# Write your MySQL query statement below SELECT DISTINCT s4.id,s4.date,s4.people FROM stadium s1,stadium s2,stadium s3,stadium s4 WHERE s1.id+1=s2.id AND s2.id+1=s3.id AND s1.people>=100 AND s2.people>=100 AND s3.people>=100 AND s4.id IN (s1.id,s2.id,s3.id)
标签:span 连续 people class where 要求 state mysq style
原文地址:https://www.cnblogs.com/JAYPARK/p/10356469.html