猪按查询排序
grunt> dump jn;
(k1,k4,10)
(k1,k5,15)
(k2,k4,9)
(k3,k4,16)
grunt> jn = group jn by $1;
grunt> dump jn;
(k4,{(k1,k4,10),(k2,k4,9),(k3,k4,16)})
(k5,{(k1,k5,15)})
现在,从这里我想要以下输出:
(k4,{(k3,k4,16),(k1,k4,10)})
(k5,{(k1,k5,15)})
基本上,我想对数字进行排序:10,9,16 并为每行选择前 2 个。
我该怎么做?
grunt> dump jn;
(k1,k4,10)
(k1,k5,15)
(k2,k4,9)
(k3,k4,16)
grunt> jn = group jn by $1;
grunt> dump jn;
(k4,{(k1,k4,10),(k2,k4,9),(k3,k4,16)})
(k5,{(k1,k5,15)})
Now, from here I want the following output :
(k4,{(k3,k4,16),(k1,k4,10)})
(k5,{(k1,k5,15)})
Bascially, I want to sort on the numbers : 10,9,16 and select the top 2 for every row.
How do I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这类似于这个 问题,您可以使用a 嵌套 FOREACH,例如:
This is similar to this question and you could use a Nested FOREACH, e.g.: