From the course: MySQL Data Analysis

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Multiple dimension GROUP BY clauses

Multiple dimension GROUP BY clauses - MySQL Tutorial

From the course: MySQL Data Analysis

Multiple dimension GROUP BY clauses

- [Instructor] All right, the next thing we're going to do is show you how to GROUP BY multiple dimensions at the same time. You can use GROUP BY with multiple columns by listing those columns and separating them with a comma. This lets you create groups and subgroups in your result set. For Excel users, you'll realize this is very similar to doing PivotTables with multiple row or column labels. My pro tip for multiple GROUP BY is to think about your dimensions and trending them over time. For example, you may have a certain customer segment and you may want to create monthly or weekly trends. You can do this by first grouping by customer segment, and then grouping by whatever time dimension you're interested in. Here's how the query syntax looks. You see we've got a SELECT with two dimensions, and then one aggregate function as our metric. And we see those two dimensions appear in the GROUP BY. Notice how the dimensions are separated with commas the same way we do when we grab…

Contents