A GROUP BY statement groups a result set by one or more columns.

Syntax

SELECT [ DISTINCT ]
{ * | projectItem [, projectItem ]* }
FROM tableExpression
[ GROUP BY { groupItem [, groupItem ]* } ];

Example

  • Test data
    Customer OrderPrice
    Bush 1000
    Carter 1600
    Bush 700
    Bush 300
    Adams 2000
    Carter 100
  • Test statement
    SELECT Customer,SUM(OrderPrice) FROM xxx
    GROUP BY Customer;
    
  • Test result
    Customer SUM(OrderPrice)
    Bush 2000
    Carter 1700
    Adams 2000