I have a table with over 30K rows and multiple columns.
Example:
id | year | make | model | color
1 | 2001 | gm | truck | red
2 | 2004 | gm | truck | green
3 | 2001 | nissan | Max | yellow
4 | 2001 | gm | truck | blue
5 | 2002 | gm | truck | green
6 | 2001 | nissan | Sentra | green
Since there are many color for each make model and year, I need to find out how many color for each vehicle.
Desired Results:
2001 Nissan Max 5 colors
2001 GM Truck 10 colors
No need to know what colors just how many colors.
I tried the following:
SELECT COUNT(DISTINCT make||model||year) AS number FROM colors LIMIT 10
Any help would be much appreciated
You almost had it:
SELECT make,
model,
year,
COUNT(DISTINCT color) AS number
FROM colors
GROUP BY make, model, year
LIMIT 10;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With