【问题标题】:Hive tables join with countHive 表加入计数
【发布时间】:2019-08-19 15:17:37
【问题描述】:

假设有两个表,usercomments。以下是每个表中的字段,

用户

userid
username

评论

commentID
commentDescription
userid

编写查询以查找拥有超过 2 个 cmets 的用户

o/p 文件

userid
username
commentDescription

【问题讨论】:

    标签: join hive inner-join hiveql


    【解决方案1】:
    select u.userid,
           u.username,
           c.commentDescription 
      from user u
           inner join (select c.userid, c.commentDescription, 
                              count(*) over(partition by userid) cnt
                         from comments c
                      ) c 
            on u.userid=c.userid and c.cnt>2; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多