GROUPING SETS

GROUPING SETS make it possible to apply many GROUP BY clauses in one single query. Moreover, this new feature introduces the notion of a ROLLUP,  which is an extra row added to the result set that gives a summary of the results as a super-aggregate of previously returned values. Let's give a very simple example using the employees table in the test database. Let's execute the following query in the phpMyAdmin web interface:

SELECT superior AS manager_id, SUM(salary)FROM employeesWHERE superior IS NOT NULLGROUP BY manager_id, salary;

Once executed, you should see this result:

GROUPING SETS make it possible to apply many GROUP ...

Get Mastering The Faster Web with PHP, MySQL, and JavaScript 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.