配置单元表与count联接

nx7onnlm  于 2021-06-24  发布在  Hive
关注(0)|答案(1)|浏览(382)

假设有两张table, user 以及 comments . 下面是每个表中的字段,
用户:

userid
username

评论:

commentID
commentDescription
userid

编写一个查询以查找有2条以上评论的用户
o/p文件:

userid
username
commentDescription
mlnl4t2r

mlnl4t2r1#

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;

相关问题