Mysql query: count and distinct
Posted
by
Azevedo
on Stack Overflow
See other posts from Stack Overflow
or by Azevedo
Published on 2013-06-28T22:11:05Z
Indexed on
2013/06/28
22:21 UTC
Read the original article
Hit count: 224
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!
© Stack Overflow or respective owner