Skip to content

Commit a4d944d

Browse files
authored
feat: add sql solution to lc problem: No.1369 (doocs#797)
No.1369.Get the Second Most Recent Activity
1 parent 9e864fd commit a4d944d

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

solution/1300-1399/1369.Get the Second Most Recent Activity/README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,18 @@ Bob 只有一条记录,我们就取这条记录</pre>
6767
### **SQL**
6868

6969
```sql
70-
70+
SELECT
71+
username,
72+
activity,
73+
startdate,
74+
enddate
75+
FROM (SELECT
76+
*,
77+
RANK() OVER (PARTITION BY username ORDER BY startdate DESC) rk,
78+
COUNT(username) OVER (PARTITION BY username) AS cnt
79+
FROM UserActivity) a
80+
WHERE a.rk = 2
81+
OR a.cnt = 1;
7182
```
7283

7384
<!-- tabs:end -->

solution/1300-1399/1369.Get the Second Most Recent Activity/README_EN.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@ Bob only has one record, we just take that one.
6363
### **SQL**
6464

6565
```sql
66-
66+
SELECT
67+
username,
68+
activity,
69+
startdate,
70+
enddate
71+
FROM (SELECT
72+
*,
73+
RANK() OVER (PARTITION BY username ORDER BY startdate DESC) rk,
74+
COUNT(username) OVER (PARTITION BY username) AS cnt
75+
FROM UserActivity) a
76+
WHERE a.rk = 2
77+
OR a.cnt = 1;
6778
```
6879

6980
<!-- tabs:end -->
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
SELECT
2+
username,
3+
activity,
4+
startdate,
5+
enddate
6+
FROM (SELECT
7+
*,
8+
RANK() OVER (PARTITION BY username ORDER BY startdate DESC) rk,
9+
COUNT(username) OVER (PARTITION BY username) AS cnt
10+
FROM UserActivity) a
11+
WHERE a.rk = 2
12+
OR a.cnt = 1;

0 commit comments

Comments
 (0)