SQL GROUP BY Clause in SQL

The SQL GROUP BY Clause is used along with the group functions to retrieve data grouped according to one or more columns.

For Example: If you want to know the total order received  by date then use group by:

SELECT CreatedOnUtc AS [ORDER DATE],COUNT(*) AS [TOTAL ORDER] FROM [Order]
GROUP BY CreatedOnUtc

 

NOTE: The group by clause should contain all the columns in the select list expect those used along with the group functions.

SELECT CreatedOnUtc AS [ORDER DATE],COUNT(*) AS [TOTAL ORDER],ShippingMethod FROM [Order]
GROUP BY CreatedOnUtc,ShippingMethod


Leave a Reply

Your email address will not be published. Required fields are marked *