Skip to content

Commit

Permalink
Create human-traffic-of-stadium.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 authored Nov 9, 2017
1 parent 8a7560c commit 9b966ac
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions MySQL/human-traffic-of-stadium.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Time: O(n^3)
# Space: O(n^3)

SELECT DISTINCT s1.*
FROM stadium AS s1, stadium AS s2, stadium AS s3
WHERE s1.people >= 100 AND s2.people >= 100 AND s3.people >= 100
AND
(
(s2.id = s1.id + 1 AND s3.id = s2.id + 1 AND s3.id = s1.id + 2) -- s1, s2, s3
OR
(s1.id = s2.id + 1 AND s3.id = s1.id + 1 AND s3.id = s2.id + 2) -- s2, s1, s3
OR
(s3.id = s2.id + 1 AND s1.id = s3.id + 1 AND s1.id = s2.id + 2) -- s2, s3, s1
)
ORDER BY s1.id
;

0 comments on commit 9b966ac

Please sign in to comment.