[英]hive sql get min and max values of multiple records
I have a query which results are 我有一个查询,结果是
fruit street inventory need to_buy
banana 123 15 99 22
apple 4 32 68 44
banana 789 01 32 11
apple 9832 0 99 94
apple 85 839 12 48
banana 832 77 05 55
I want to get the minimum values for inventory, and need, and get the max to_buy value. 我想获取库存和需求的最小值,并获取最大的to_buy值。 but only have one record of each 'fruit'. 但每个“水果”只有一个记录。 the 'street' column is irrelevant and is not needed in the final result. “街道”列无关紧要,在最终结果中不需要。 The final result should look like 最终结果应该像
fruit inventory(min) need(min) to_buy(max)
banana 01 05 55
apple 0 12 94
Also the initial records may not be ordered at first so there are more 'fruits' inserted at random How can i achieve the desired result above? 另外,初始记录可能不会一开始就排序,因此会随机插入更多“水果”,我如何才能达到上述预期效果?
Try this: 尝试这个:
SELECT MIN(inventory), MIN(need), MAX(to_buy)
FROM tableName
GROUP BY fruits
This one should work: 这应该工作:
SELECT fruits, MIN(inventory), MIN(need), MAX(to_buy)
FROM <table_name>
GROUP BY fruits
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.