Group By Clause Examples

Example 1

Select id, product, avg(amount), sum(amount), max(amount), count(*)
  From sales
Group By id, product
Order By id ;

Example 2

Select count(name)
  From customers
Group By city
Order By count(customer_id);


Example 3

Select
 Case When price between 100 and 200 then 'Price Low: 100-200'
           When price between 201 and 300 then 'Price High: 201-300'
           Else 'Price Very High'
           End
           As test,
 count(*) num_prices
 Group By
 Case When price between 100 and 200 then 'Price Low: 100-200'
           When price between 201 and 300 then 'Price High: 201-300'
           Else 'Price Very High'
           End