加入收藏 | 设为首页 | 会员中心 | 我要投稿 北几岛 (https://www.beijidao.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

php – 选择DISTINCT多列MySQL

发布时间:2021-08-28 03:47:34 所属栏目:大数据 来源: https://www.jb51.cc
导读:我有一个超过30K行和多列的表. 例: id | year | make | model | color1 | 2001 | gm | truck | red2 | 2004 | gm | truck | green3 | 2001 | nissan | Max | yellow4 | 2001 | gm | truck | blue5 | 2002 | gm | truck | green6 | 2001 | nissan | Sentra |

我有一个超过30K行和多列的表.

例:

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

由于每个品牌和年份有很多颜色,我需要找出每辆车的颜色.

期望的结果:

2001 Nissan Max 5 colors
2001 GM Truck 10 colors

无需知道颜色有多少颜色.

我尝试了以下方法:

SELECT COUNT(DISTINCT make||model||year) AS number FROM colors LIMIT 10

任何帮助将非常感激

解决方法:

你几乎拥有它:

SELECT make, model, year, COUNT(DISTINCT color) AS number FROM colors group by make, model, year LIMIT 10

(编辑:北几岛)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读