Mysql query: count and distinct
- by Azevedo
I have this hypotetical MySQL table:
TABLE cars: (year, color, brand)
How do I count # of cars grouped by brand and year? I mean, how can I get to know how many colors are there grouped by brand like:
brand "GM": total # of colors: 8.
brand "GM": total # of years (grouped together): 14 (meaning there are count of 14 different years).
brand "TOYOTA": total # of colors: 3.
brand "TOYOTA": total # of years (grouped together): 10 (meaning there are count of 14 different years)
I tried playing some queries with COUNT, DISTINCT, GROUP BY but I can't get to it.
Actually I'm trying to get the 2 queries...
+-------+---------------+
| brand | count(colors) |
+-------+---------------+
+-------+--------------+
| brand | count(years) |
+-------+--------------+
thanks a lot!