SQL group by usage
Group by, Count, minimum, maximum, or used to generate a total. Their output values are the same summary, listing the final appearance in each column in a report. You can also use these functions to output the total value of the score. The value in the entire column is split by the special clause group. It is combined into a record that all records share the same value in a field or field combination. The group by clause can group the results of one or more columns.
SELECT column_name_1,..., column_name_n, aggregate_function (expression)
FROM table_name
[WHERE condition]
Group by column_name1,..., column_name_n
The where clause is optional. If the keyword is present in the SQL statement, it is mentioned in the GROUP BY clause.
Example #1
Select Item, Sum (Price) as TotalSum
From Antiques
Group by Item
This query returns different items and the so-called 'field list totalsum' counts the sum of antique results to supply each item.
Example #2
Select Item, Max (Price) as MaxPrice
From Antiques
Group by Item
This returns the name of each project and its highest price.
Example #3
Select SellerID, Count (*) as Number_of_Sellers
From Antiques
Where BuyerID = 15
Group by SellerID