1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (English)/体育馆的人流量(English) [human-traffic-of-stadium].html

55 lines
1.9 KiB
HTML
Raw Permalink Normal View History

2022-03-27 20:46:41 +08:00
<p>Table: <code>Stadium</code></p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| id | int |
| visit_date | date |
| people | int |
+---------------+---------+
2023-12-09 18:42:21 +08:00
visit_date is the column with unique values for this table.
2022-03-27 20:46:41 +08:00
Each row of this table contains the visit date and visit id to the stadium with the number of people during the visit.
2023-12-09 18:42:21 +08:00
As the id increases, the date increases as well.
2022-03-27 20:46:41 +08:00
</pre>
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p>Write a solution to display the records with three or more rows with <strong>consecutive</strong> <code>id</code>&#39;s, and the number of people is greater than or equal to 100 for each.</p>
2022-03-27 20:46:41 +08:00
<p>Return the result table ordered by <code>visit_date</code> in <strong>ascending order</strong>.</p>
2023-12-09 18:42:21 +08:00
<p>The result format is in the following example.</p>
2022-03-27 20:46:41 +08:00
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p><strong class="example">Example 1:</strong></p>
2022-03-27 20:46:41 +08:00
<pre>
<strong>Input:</strong>
Stadium table:
+------+------------+-----------+
| id | visit_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-09 | 188 |
+------+------------+-----------+
<strong>Output:</strong>
+------+------------+-----------+
| id | visit_date | people |
+------+------------+-----------+
| 5 | 2017-01-05 | 145 |
| 6 | 2017-01-06 | 1455 |
| 7 | 2017-01-07 | 199 |
| 8 | 2017-01-09 | 188 |
+------+------------+-----------+
<strong>Explanation:</strong>
The four rows with ids 5, 6, 7, and 8 have consecutive ids and each of them has &gt;= 100 people attended. Note that row 8 was included even though the visit_date was not the next day after row 7.
The rows with ids 2 and 3 are not included because we need at least three consecutive ids.
</pre>