LeetCode - 601. Human Traffic of Stadium
X city built a new stadium, each day many people visit it and the stats are saved as these columns: id, date, people
Please write a query to display the records which have 3 or more consecutive rows and the amount of people more than 100(inclusive).
For example, the table 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 |
+------+------------+-----------+
For the sample data above, the output is:
+------+------------+-----------+
| id | date | people |
+------+------------+-----------+
| 5 | 2017-01-05 | 145 |
| 6 | 2017-01-06 | 1455 |
| 7 | 2017-01-07 | 199 |
| 8 | 2017-01-08 | 188 |
+------+------------+-----------+
# Write your MySQL query statement below
SELECT
DISTINCT t1.*
FROM
stadium t1,
stadium t2,
stadium t3
WHERE
t1.people >= 100
AND t2.people >= 100
AND t3.people >= 100
AND (
(
t1.id - t2.id = 1
AND t1.id - t3.id = 2
AND t2.id - t3.id = 1
)
OR (
t2.id - t1.id = 1
AND t2.id - t3.id = 2
AND t1.id - t3.id = 1
)
OR (
t3.id - t2.id = 1
AND t2.id - t1.id = 1
AND t3.id - t1.id = 2
)
)
ORDER BY
t1.id
LeetCode - 601. Human Traffic of Stadium的更多相关文章
- 【leetcode database】Human Traffic of Stadium
X city built a new stadium, each day many people visit it and the stats are saved as these columns: ...
- [SQL]LeetCode601. 体育馆的人流量 | Human Traffic of Stadium
SQL架构 Create table If Not Exists stadium (id int, visit_date DATE NULL, people int) Truncate table s ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
- leetcode hard
# Title Solution Acceptance Difficulty Frequency 4 Median of Two Sorted Arrays 27.2% Hard ...
- SQL练习——LeetCode解题和总结(1)
只用于个人的学习和总结. 178. Rank Scores 一.表信息 二.题目信息 对上表中的成绩由高到低排序,并列出排名.当两个人获得相同分数时,取并列名次,且名词中无断档. Write a SQ ...
- Swift LeetCode 目录 | Catalog
请点击页面左上角 -> Fork me on Github 或直接访问本项目Github地址:LeetCode Solution by Swift 说明:题目中含有$符号则为付费题目. 如 ...
- 【sql】leetcode习题 (共 42 题)
[175]Combine Two Tables (2018年11月23日,开始集中review基础) Table: Person +-------------+---------+ | Column ...
- 五、Pandas玩转数据
Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...
- [leetcode]Permutation Sequence @ Python
原题地址:https://oj.leetcode.com/submissions/detail/5341904/ 题意: The set [1,2,3,…,n] contains a total of ...
随机推荐
- 【深度学习系列】CNN模型的可视化
前面几篇文章讲到了卷积神经网络CNN,但是对于它在每一层提取到的特征以及训练的过程可能还是不太明白,所以这节主要通过模型的可视化来神经网络在每一层中是如何训练的.我们知道,神经网络本身包含了一系列特征 ...
- 【开发技术】java+mysql 更改表字段的步骤
1).首先通过SQL更改MYSQL库中的表结构(下面是一些例子) ALTER TABLE `illegalactivate` ADD `macethaddress` varchar(250) NOT ...
- 提高PHP性能的一些小知识
自PHP面世起以其良好的跨平台性,高效的开发机制有WEB领域占有很大份额.因为它的运行机制是脚本解释运行执行后相关资源都会被回收,所以PHP开发人员很少关心他的资源占用所导致性能问题,但本人是个追求极 ...
- MVVM探索:从ViewModel关闭Window的最佳实践
在WPF里使用MVVM开发的时候,似乎总是不可避免的会遇到这样一个问题:ViewModel在处理完业务之后需要关闭这个Window,这时候要怎么处理? 网上有很多解决方案:有的在ViewModel抛出 ...
- python_如何对字典进行排序?
案例: 某班英语成绩以字典的形式存储为: {'lili':78, 'jin':50, 'liming': 30, ......} 依据成绩高低,进行学生成绩排名 如何对字典排序? 方法1: #!/us ...
- linkin大话数据结构--数组
数组概述:如何正确理解数组?数组也是一种类型 数组是多个相同类型数据的组合,实现对这些数据的统一管理.数组属引用类型,数组型数据是对象(Object),数组中的每个元素相当于该对象的成员变量数组中的元 ...
- TinyXML 的简单介绍以及使用
先说几句重点: 1,tinyxml 生成或解析XML非常好用 2,tinyxml 利用DOM(文档对象模型)操作XML,根节点与各个子节点相当于形成一棵树 3,只要你了解tinyxml的用法,可以只n ...
- nagios中监测dns 227.7.128.68的网络状态
[root@nhserver2 ~]# cd /usr/local/nagios/etc/objects [root@nhserver2 objects]# vim hosts_dns.cfgdefi ...
- 【转】Shell执行MySql操作
mysql -hhostname -Pport -uusername -ppassword -e 相关mysql的sql语句,不用在mysql的提示符下运行mysql,即可以在shell中操作m ...
- unicode文件处理(如果是ANSI编码就不需要了)
1.unicode文件的打开必须用rb模式. 3.wchar_t str[100] = { 0 }; 这个占200个字节. 2.宽字符对应的处理 fgetc fgetwc fputc fputwc f ...