From 9b966ac16a6c3936aaf9505d6618e8721d846dac Mon Sep 17 00:00:00 2001 From: kamyu Date: Thu, 9 Nov 2017 07:41:35 -0600 Subject: [PATCH] Create human-traffic-of-stadium.sql --- MySQL/human-traffic-of-stadium.sql | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 MySQL/human-traffic-of-stadium.sql diff --git a/MySQL/human-traffic-of-stadium.sql b/MySQL/human-traffic-of-stadium.sql new file mode 100644 index 000000000..fcf908393 --- /dev/null +++ b/MySQL/human-traffic-of-stadium.sql @@ -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 +;