[英]Select DISTINCT multiple columns MySQL
I have a table with over 30K rows and multiple columns.我有一个超过 30K 行和多列的表。
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.