当我在SQL Server中有多个列时如何使用DISTINCT [英] how to use DISTINCT when I have multiple column in sql server

查看:80
本文介绍了当我在SQL Server中有多个列时如何使用DISTINCT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询:

select carBrand, carYear, carModel from cars;

我想要的是仅获取不同的汽车名称。

what I want is to get only different car names.

我写了这个,但这不是我想要的。

I wrote this, but it is not what i want.

select DISTINCT carBrand, carYear, carModel from Cars;

我该如何解决这个问题?

how can I solve this problem?

推荐答案

尝试

SELECT carBrand , carYear ,carModel 
FROM Cars 
GROUP BY carBrand , carYear ,carModel;

这篇关于当我在SQL Server中有多个列时如何使用DISTINCT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆