Why Group Data?

Grouping data is the process of combining columns with duplicate values in a logical order. For example, a database may contain information about employees; many employees live in different cities, while some employees live in the same city. You may want to execute a query that shows employee information for each particular city. You are grouping employee information by city, and a summarized report is created.

Suppose that you wanted to figure the average salary paid to employees according to each city. You would do this by using the aggregate function AVG on the SALARY column, as you learned last hour, and by using the GROUP BY clause to group the output by city.

Grouping data is accomplished through the use of the GROUP BY ...

Get Sams Teach Yourself SQL in 24 Hours, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.