File tree 3 files changed +90
-2
lines changed
solution/1900-1999/1949.Strong Friendship
3 files changed +90
-2
lines changed Original file line number Diff line number Diff line change 79
79
<!-- 这里可写当前语言的特殊实现逻辑 -->
80
80
81
81
``` 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 ;
83
112
```
84
113
85
114
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -72,7 +72,36 @@ We did not include the friendship of users 2 and 3 because they only have two co
72
72
### ** SQL**
73
73
74
74
``` 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 ;
76
105
```
77
106
78
107
<!-- tabs:end -->
Original file line number Diff line number Diff line change
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 ;
You can’t perform that action at this time.
0 commit comments