数据集 - 包含PostId和userID
20 1
21 2
45 3
85 1
48 1
98 1
74 1
96 2
63 2
33 3
44 3
55 3
66 3
77 3
我想访问最大号为no的userID。的帖子
PIG代码
A =加载'/home/cloudera/Desktop/post.txt'为(postid:chararray,userid:chararray);
B =加载'/home/cloudera/Desktop/user.txt'为(名称:chararray,id:chararray);
C =用户ID的A组;
D = foreach C生成组,COUNT(A.postid)作为计数;
E =按计数DESC排序D;
F =限制D 1;
它提供输出 -
(3,6)
现在,在执行F语句后,从user.txt访问用户名的PIG语句是什么,其id与A.userid相同?
答案 0 :(得分:1)
添加另一个语句以从关系F
获取第一列G = FOREACH F GENERATE $0;
DUMP G;
答案 1 :(得分:0)
使用以下SQL语句获取所需的输出
declare @var int = (select max(cn) from (select count(post) cn from temp group by userid) c)
select * from (select userid,count(post) as pso from temp group by userid ) as c where pso = @var