Skip to content

Commit 43777c6

Browse files
committed
feat: add sql solution to lc problem: No.1951
No.1951.All the Pairs With the Maximum Number of Common Followers
1 parent ab74313 commit 43777c6

File tree

3 files changed

+72
-2
lines changed

3 files changed

+72
-2
lines changed

solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,30 @@ Result 表:
7373
<!-- 这里可写当前语言的特殊实现逻辑 -->
7474

7575
```sql
76-
76+
# Write your MySQL query statement below
77+
with t as (
78+
select
79+
r1.user_id user1_id,
80+
r2.user_id user2_id,
81+
rank() over(
82+
order by
83+
count(1) desc
84+
) rk
85+
from
86+
Relations r1
87+
join Relations r2 on r1.follower_id = r2.follower_id
88+
and r1.user_id < r2.user_id
89+
group by
90+
r1.user_id,
91+
r2.user_id
92+
)
93+
select
94+
user1_id,
95+
user2_id
96+
from
97+
t
98+
where
99+
rk = 1;
77100
```
78101

79102
<!-- tabs:end -->

solution/1900-1999/1951.All the Pairs With the Maximum Number of Common Followers/README_EN.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,30 @@ Note that we do not have any information about the users that follow users 3, 4,
6767
### **SQL**
6868

6969
```sql
70-
70+
# Write your MySQL query statement below
71+
with t as (
72+
select
73+
r1.user_id user1_id,
74+
r2.user_id user2_id,
75+
rank() over(
76+
order by
77+
count(1) desc
78+
) rk
79+
from
80+
Relations r1
81+
join Relations r2 on r1.follower_id = r2.follower_id
82+
and r1.user_id < r2.user_id
83+
group by
84+
r1.user_id,
85+
r2.user_id
86+
)
87+
select
88+
user1_id,
89+
user2_id
90+
from
91+
t
92+
where
93+
rk = 1;
7194
```
7295

7396
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Write your MySQL query statement below
2+
with t as (
3+
select
4+
r1.user_id user1_id,
5+
r2.user_id user2_id,
6+
rank() over(
7+
order by
8+
count(1) desc
9+
) rk
10+
from
11+
Relations r1
12+
join Relations r2 on r1.follower_id = r2.follower_id
13+
and r1.user_id < r2.user_id
14+
group by
15+
r1.user_id,
16+
r2.user_id
17+
)
18+
select
19+
user1_id,
20+
user2_id
21+
from
22+
t
23+
where
24+
rk = 1;

0 commit comments

Comments
 (0)