zoukankan      html  css  js  c++  java
  • 601. 体育馆的人流量

    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 * from (
    	select a.* from stadium a 
    		join stadium b on b.id = a.id + 1
    		join stadium c on c.id = a.id + 2
    	where a.people >= 100 and b.people >= 100 and c.people >= 100
    	union
    	select b.* from stadium a 
    		join stadium b on b.id = a.id + 1
    		join stadium c on c.id = a.id + 2
    	where a.people >= 100 and b.people >= 100 and c.people >= 100
    	union
    	select c.* from stadium a 
    		join stadium b on b.id = a.id + 1
    		join stadium c on c.id = a.id + 2
    	where a.people >= 100 and b.people >= 100 and c.people >= 100
    )a order by id;
    
  • 相关阅读:
    2021.5.10-(叶子相似的树)
    2021.5.8-N皇后(回溯)
    2021.5.6-(雪糕最大数)
    2021.4.23刷题(回溯-全排列)
    可持久化动态图上树状数组维护01背包
    Infinite String Comparision
    第6章 操作系统 存储器管理(二)
    markdown
    操作系统 第6章 存储管理(一)
    操作系统 第五章 死锁 (二)
  • 原文地址:https://www.cnblogs.com/ccXgc/p/9334710.html
Copyright © 2011-2022 走看看