我试图理解什么是二级追随者的意思? 我有一个表格,后面有两列:followee和followers
Followee Follower
A B
B C
B D
B E
A F
F G
F H
B H
什么是找到第二学位的追随者?
答案 0 :(得分:1)
要详细说明我的评论,您可以通过自我加入来看到这一点。
declare @table table(Followee char(1), Follower char(1))
insert into @table
values
('A','B'),
('B','C'),
('B','D'),
('B','E'),
('A','F'),
('F','G'),
('F','H'),
('B','H')
select
l.Followee
,f.Follower as SecondDegreeFollower
,count(*) as CT
from
@table l
left join
@table f on f.Followee = l.Follower
where
f.Follower is not null
group by
l.Followee
,f.Follower
<强>返回强>
+----------+----------------------+----+
| Followee | SecondDegreeFollower | CT |
+----------+----------------------+----+
| A | C | 1 |
| A | D | 1 |
| A | E | 1 |
| A | G | 1 |
| A | H | 2 |
+----------+----------------------+----+