Skip to content

Commit 7fb26e5

Browse files
refactor 614
1 parent c6a3b6e commit 7fb26e5

File tree

1 file changed

+0
-28
lines changed

1 file changed

+0
-28
lines changed

Diff for: database/_614.sql

-28
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
--614. Second Degree Follower
2-
--In facebook, there is a follow table with two columns: followee, follower.
3-
--
4-
--Please write a sql query to get the amount of each follower’s follower if he/she has one.
5-
--
6-
--For example:
7-
--
8-
--+-------------+------------+
9-
--| followee | follower |
10-
--+-------------+------------+
11-
--| A | B |
12-
--| B | C |
13-
--| B | D |
14-
--| D | E |
15-
--+-------------+------------+
16-
--should output:
17-
--+-------------+------------+
18-
--| follower | num |
19-
--+-------------+------------+
20-
--| B | 2 |
21-
--| D | 1 |
22-
--+-------------+------------+
23-
--Explaination:
24-
--Both B and D exist in the follower list, when as a followee, B's follower is C and D, and D's follower is E. A does not exist in follower list.
25-
--Note:
26-
--Followee would not follow himself/herself in all cases.
27-
--Please display the result in follower's alphabet order.
28-
291
select f1.follower, count(distinct f2.follower) as num
302
from follow f1
313
inner join follow f2 on f1.follower = f2.followee

0 commit comments

Comments
 (0)