GROUP BY - little gem for aggregating data
When you need to count (or sum, or aggregate) data and see the results "for each of something", then GROUP BY is probably what you want.
Note: you have to make sure that the SELECT columns appear in the GROUP BY clause - up to the last aggregator.
The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.
SQL GROUP BY Syntax
| SELECT column_name, aggregate_function(column_name) FROM table_name WHERE column_name operator value GROUP BY column_name |
"