Microsoft SQL Server 简单分组
示例
订单表
按特定列分组时,仅返回此列的唯一值。
SELECT customerId FROM orders GROUP BY customerId;
返回值:
聚合函数count()适用于每个组,而不适用于完整的表:
SELECT customerId, COUNT(productId) as numberOfProducts, sum(price) as totalPrice FROM orders GROUP BY customerId;
返回值: