Skip to content

Commit d56d4d9

Browse files
authored
Create activity-participants.sql
1 parent 3fbb648 commit d56d4d9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

MySQL/activity-participants.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
SELECT activity
5+
FROM friends
6+
GROUP BY activity
7+
HAVING Count(1) NOT IN (SELECT Max(counts)
8+
FROM (SELECT Count(1) AS counts
9+
FROM friends
10+
GROUP BY activity
11+
ORDER BY NULL) a
12+
UNION ALL
13+
SELECT Min(counts)
14+
FROM (SELECT Count(1) AS counts
15+
FROM friends
16+
GROUP BY activity
17+
ORDER BY NULL) b)
18+
ORDER BY NULL;

0 commit comments

Comments
 (0)