SQL GROUP BY




The SQL GROUP BY clause is used in collaboration with the SELECT statement to arrange identical data into groups.

The GROUP BY clause follows the WHERE clause in a SELECT statement and precedes the ORDER BY clause.

SYNTAX:

SELECT SUM(column_name)
FROM   table_name
WHERE  CONDITION
GROUP BY column_name;

EXAMPLE:

SELECT NAME, SUM(SALARY) FROM CUSTOMERS
     GROUP BY NAME;

Displays  the total amount of salary on each customer.

No comments:

Post a Comment