ITPub博客

首页 > 大数据 > 数据分析 > 计算好友对数

计算好友对数

原创 数据分析 作者:liuhongwei 时间:2021-03-15 10:22:17 0 删除 编辑

                   

                   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/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: airflow性能优化
下一篇: 数据库3范式详解
请登录后发表评论 登录
全部评论

注册时间:2021-03-15

  • 博文量
    8
  • 访问量
    7052