Skip to content

Commit d4c69a9

Browse files
authored
Create 1369-get-the-second-most-recent-activity.sql
1 parent b8d7d69 commit d4c69a9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Write your MySQL query statement below
2+
SELECT *
3+
FROM UserActivity
4+
GROUP BY username
5+
HAVING COUNT(*) = 1
6+
7+
UNION ALL
8+
9+
SELECT u1.*
10+
FROM UserActivity u1
11+
LEFT JOIN UserActivity u2
12+
ON u1.username = u2.username AND u1.endDate < u2.endDate
13+
GROUP BY u1.username, u1.endDate
14+
HAVING COUNT(u2.endDate) = 1;

0 commit comments

Comments
 (0)