sql - 如何在 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 的最高数量
解决方案
尝试如下
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)
推荐阅读
- c - C - 按钮按下一次注册两次 - MSP430
- javascript - 使用 fetch javascript 查询字符串
- kubernetes - Kubernetes 指标服务器没有响应
- mongodb - 从 MongoDB 的数组中删除一个元素?
- java - 将 JUnit @BeforeClass 与 Cucumber 一起使用...有效吗?
- elasticsearch - 每个类别的最新文件?
- ios - iOS 没有正确杀死应用程序 - Ionic
- java - 当使用 null 显式初始化时,可序列化类中的映射显示为违反声纳
- asp.net-core-mvc - ViewComponent 的 XUnit 测试返回空结果?
- python - 如何通过导入的函数从 python 中另一个脚本调用的脚本中获取目录