Skip to content

Commit 4d38082

Browse files
committed
feat: add sql solution to lc problem: No.1949
No.1949.Strong Friendship
1 parent 43777c6 commit 4d38082

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

solution/1900-1999/1949.Strong Friendship/README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,36 @@
7979
<!-- 这里可写当前语言的特殊实现逻辑 -->
8080

8181
```sql
82-
82+
# Write your MySQL query statement below
83+
with t as (
84+
select
85+
*
86+
from
87+
Friendship
88+
union
89+
all
90+
select
91+
user2_id,
92+
user1_id
93+
from
94+
Friendship
95+
)
96+
select
97+
t1.user1_id,
98+
t1.user2_id,
99+
count(1) common_friend
100+
from
101+
t t1
102+
join t t2 on t1.user2_id = t2.user1_id
103+
join t t3 on t1.user1_id = t3.user1_id
104+
where
105+
t3.user2_id = t2.user2_id
106+
and t1.user1_id < t1.user2_id
107+
group by
108+
t1.user1_id,
109+
t1.user2_id
110+
having
111+
count(1) >= 3;
83112
```
84113

85114
<!-- tabs:end -->

solution/1900-1999/1949.Strong Friendship/README_EN.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,36 @@ We did not include the friendship of users 2 and 3 because they only have two co
7272
### **SQL**
7373

7474
```sql
75-
75+
# Write your MySQL query statement below
76+
with t as (
77+
select
78+
*
79+
from
80+
Friendship
81+
union
82+
all
83+
select
84+
user2_id,
85+
user1_id
86+
from
87+
Friendship
88+
)
89+
select
90+
t1.user1_id,
91+
t1.user2_id,
92+
count(1) common_friend
93+
from
94+
t t1
95+
join t t2 on t1.user2_id = t2.user1_id
96+
join t t3 on t1.user1_id = t3.user1_id
97+
where
98+
t3.user2_id = t2.user2_id
99+
and t1.user1_id < t1.user2_id
100+
group by
101+
t1.user1_id,
102+
t1.user2_id
103+
having
104+
count(1) >= 3;
76105
```
77106

78107
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Write your MySQL query statement below
2+
with t as (
3+
select
4+
*
5+
from
6+
Friendship
7+
union
8+
all
9+
select
10+
user2_id,
11+
user1_id
12+
from
13+
Friendship
14+
)
15+
select
16+
t1.user1_id,
17+
t1.user2_id,
18+
count(1) common_friend
19+
from
20+
t t1
21+
join t t2 on t1.user2_id = t2.user1_id
22+
join t t3 on t1.user1_id = t3.user1_id
23+
where
24+
t3.user2_id = t2.user2_id
25+
and t1.user1_id < t1.user2_id
26+
group by
27+
t1.user1_id,
28+
t1.user2_id
29+
having
30+
count(1) >= 3;

0 commit comments

Comments
 (0)