首页 > 解决方案 > 如何在 HIVE 中找到每个唯一 ID 的总和和最大值?

问题描述

基本上我该怎么转

id name   quantity 
1  Jerry      1
1  Jerry      2
1  Nana       1
2  Max        4
2  Lenny      3

进入

id name   quantity
1  Jerry     3
2  Max       4

在 HIVE 中?我想总结并找到每个唯一 ID 的最高数量

标签: sqlhive

解决方案


尝试如下

 with cte as    
(
 select id,name,sum(quantity) as q
 from table_name group by id,name
) select id,name,q from  cte t1
  where t1.q=( select max(q) from cte t2 where t1.id=t2.id)

推荐阅读