HOW TO USE GROUP BY CLAUSE IN SQL

GROUP BY in SQL

GROUP BY clause in SQL statements is used to group the result-set by one or more columns that have the same values. It is often used with aggregate functions like SUM, AVG, MIN, MAX & COUNT. GROUP BY clause is placed after WHERE clause.

Syntax of GROUP BY clause in SQL-

SELECT <column_name(s)>

FROM <table_name>

WHERE<condition>

GROUP BY<column_name(s)>;

Example of GROUP BY clause in SQL-

SELECT COUNT (CustomerID), Country

FROM Customers

GROUP BY Country;

–This SQL statement will list the number of customers in each country.


Leave a Reply

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