with temp as(
select 'A' as userid ,'B,C,D' as follow_list
union all
select 'B' as userid ,'A,C' as follow_list
union all
select 'C' as userid ,'D' as follow_list
)
select
count(1) --统计对儿数
from (
select
userid
,userid_f
from (
select --排序
if(userid>userid_f ,userid,userid_f) userid --大在前小在后
,if(userid>userid_f ,userid_f,userid) userid_f --大在前小在后
from temp
lateral view explode(split(follow_list,',')) t as userid_f --列转行
)t
group by userid,userid_f --去重
)t2
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69996462/viewspace-2762804/ ,如需转载,请注明出处,否则将追究法律责任。