全部产品
阿里云办公

GROUP BY语句

更新时间:2018-09-29 17:51:28

GROUP BY语句用于根据一个或多个列对结果集进行分组。

语法

  1. SELECT [ DISTINCT ]
  2. { * | projectItem [, projectItem ]* }
  3. FROM tableExpression
  4. [ GROUP BY { groupItem [, groupItem ]* } ];

示例

测试数据

Customer OrderPrice
Bush 1000
Carter 1600
Bush 700
Bush 300
Adams 2000
Carter 100

测试语句

  1. SELECT Customer,SUM(OrderPrice) FROM XXXX
  2. GROUP BY Customer;

测试结果

Customer SUM(OrderPrice)
Bush 2000
Carter 1700
Adams 2000