GROUP BY in SQL

HOW TO USE GROUP BY CLAUSE 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.


Posted

in

Tags:

Comments

Leave a Reply