Hive中的GROUP BY语句用于将相同数据行的数据进行聚合
customer_id
对订单进行分组。SELECT customer_id, COUNT(*) as order_count
FROM orders
GROUP BY customer_id;
SELECT customer_id, COUNT(*) as order_count
FROM orders
GROUP BY customer_id;
在上面的示例中,输出格式如下:
customer_id | order_count |
---|---|
1 | 5 |
2 | 3 |
3 | 7 |
每个分组列的值将用于将数据分组,而聚合列的值是对分组数据进行计算的聚合结果。