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 ...
随机推荐
- Flume介绍
Flume介绍 http://flume.apache.org/FlumeUserGuide.html 一.Flume架构图 含义 Source 规定收集数据的来源 Channel 相当于一个管道,连 ...
- JavaScript语法基础:数组的常用方法详解
本文最初发表于博客园,并在GitHub上持续更新前端的系列文章.欢迎在GitHub上关注我,一起入门和进阶前端. 以下是正文. 数组的定义 之前学习的数据类型,只能存储一个值(字符串为一个值).如果我 ...
- dede首页调用分类信息
格兰斯-与你共同开创门窗定制5G时代 5G战略--明确的,没有歧义的明亮奥尼克斯的观点与追求 {dede:channelartlist row=1} {dede:arclistsg r ...
- two Pass方法连通域检测
原理: Two-Pass方法检测连通域的原理可参见这篇博客:http://blog.csdn.net/lichengyu/article/details/13986521. 参考下面动图,一目了然. ...
- 如何从Android工程导出apk安装包
http://jingyan.baidu.com/article/1876c852b3208b890b137606.html
- java.lang.NoClassDefFoundError: javax/mail/Authenticator
摘录自:http://stackoverflow.com/questions/1630002/java-lang-noclassdeffounderror-javax-mail-authenticat ...
- jquery 遍历表格,需要表格中每个td的内容
$("table tr:gt(0)").each(function(i){ alert("这是第"+i+"行内容"); $(this).ch ...
- Spring MVC 数据校验@Valid
先看看几个关键词 @Valid @Pattern @NotNull @NotBlank @Size BindingResult 这些就是Spring MVC的数据校验的几个注解. 那怎么用呢?往下看 ...
- python_计算1+……+100中偶数和
如何计算1+--+100中偶数和? 1. 把奇数去掉,通过if,判断累加数除以2的余数,是否为1,判断是否是奇数 2. 通过continue 跳过对奇数的累加 #!/usr/bin/python3 d ...
- java —— equals 与 ==
equals 众所周知,java 中的所有的类都继承自 Object 这个超类 ,他就是Java所有类的父类或祖先类,Object类里面有一个equals方法,并且提供了默认的实现,如下所示. pub ...