Skip to content

Commit af6c87f

Browse files
authored
feat: add sql solution to lc problem: No.0602 (doocs#779)
No.0602.Friend Requests II: Who Has the Most Friends
1 parent b469947 commit af6c87f

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,19 @@ RequestAccepted 表:
7171
### **SQL**
7272

7373
```sql
74-
74+
SELECT
75+
ids AS id, COUNT(*) num
76+
FROM
77+
(SELECT
78+
requester_id AS ids
79+
FROM
80+
RequestAccepted UNION ALL SELECT
81+
accepter_id
82+
FROM
83+
RequestAccepted) t
84+
GROUP BY ids
85+
ORDER BY num DESC
86+
LIMIT 1;
7587
```
7688

7789
<!-- tabs:end -->

solution/0600-0699/0602.Friend Requests II Who Has the Most Friends/README_EN.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,19 @@ The person with id 3 is a friend of people 1, 2, and 4, so he has three friends
6060
### **SQL**
6161

6262
```sql
63-
63+
SELECT
64+
ids AS id, COUNT(*) num
65+
FROM
66+
(SELECT
67+
requester_id AS ids
68+
FROM
69+
RequestAccepted UNION ALL SELECT
70+
accepter_id
71+
FROM
72+
RequestAccepted) t
73+
GROUP BY ids
74+
ORDER BY num DESC
75+
LIMIT 1;
6476
```
6577

6678
<!-- tabs:end -->
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SELECT
2+
ids AS id, COUNT(*) num
3+
FROM
4+
(SELECT
5+
requester_id AS ids
6+
FROM
7+
RequestAccepted UNION ALL SELECT
8+
accepter_id
9+
FROM
10+
RequestAccepted) t
11+
GROUP BY ids
12+
ORDER BY num DESC
13+
LIMIT 1;
14+

0 commit comments

Comments
 (0)