5

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

1

1 Answer 1

5

You almost had it:

SELECT make,
       model,
       year,
       COUNT(DISTINCT color) AS number 
FROM colors
GROUP BY make, model, year
LIMIT 10;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.