Skip to content

task: #601 #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ Useful for preparing for technical interviews and improving your SQL skills.
- [3497. Analyze Subscription Conversion](./leetcode/medium/3497.%20Analyze%20Subscription%20Conversion.sql)
3. [Hard](./leetcode/hard/)
- [185. Department Top Three Salaries](./leetcode/hard/185.%20Department%20Top%20Three%20Salaries.sql)
- [601. Human Traffic of Stadium](./leetcode/hard/601.%20Human%20Traffic%20of%20Stadium.sql)
- [3374. First Letter Capitalization II](./leetcode/hard/3374.%20First%20Letter%20Capitalization%20II.sql)

## Contributing
Expand Down
50 changes: 50 additions & 0 deletions leetcode/hard/601. Human Traffic of Stadium.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Question 601. Human Traffic of Stadium
Link:

Table: Stadium

+---------------+---------+
| Column Name | Type |
+---------------+---------+
| id | int |
| visit_date | date |
| people | int |
+---------------+---------+
visit_date is the column with unique values for this table.
Each row of this table contains the visit date and visit id to the stadium with the number of people during the visit.
As the id increases, the date increases as well.


Write a solution to display the records with three or more rows with consecutive id's, and the number of people is greater than or equal to 100 for each.

Return the result table ordered by visit_date in ascending order.
*/

WITH more_than_100 AS (
SELECT
s1.id,
s1.id - ROW_NUMBER() OVER (ORDER BY s1.id) AS c_id
FROM Stadium AS s1
WHERE s1.people >= 100
),

three_consecutive AS (
SELECT s2.c_id
FROM more_than_100 AS s2
GROUP BY s2.c_id
HAVING COUNT(s2.c_id) >= 3
)

SELECT
s.id,
s.visit_date,
s.people
FROM Stadium AS s
INNER JOIN
more_than_100 AS mt
ON s.id = mt.id
WHERE mt.c_id IN (
SELECT tc.c_id
FROM three_consecutive AS tc
)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy