仅在一列中选择非重复记录 [英] Select non duplicate records in one column only

查看:81
本文介绍了仅在一列中选择非重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只希望在一个cloumn其他列中只有不同的值可以包含重复值,我该如何实现这个



 创建  table  test 

Id int
名称 varchar (max),
Department varchar (max ),
国家 varchar (max)

insert < span class =code-keyword> into test values 1 ' B'' IT'' India'
插入 进入 test values 2 ' B'' IT'' < span class =code-string> US')
insert into test values 3 ' C'' HR'' UK'
insert into test values 4 ' D'' HR'' 印度'
插入 进入 test 5 ' E'' IT'' US'
insert 进入 test 6 ' F'' IT'' UK'
select * 来自 test





我只想要非重复值在国家/地区列中。

从测试组中选择ID,国家/地区country FAILED

选择id,国家与测试不同FAILED

解决方案

按方法分组可行,但你需要决定你想要什么与其他列一起查看。不在group by子句中的所有列都需要具有某种聚合函数(max,min,avg等)



如何编写组的示例是这样的:



选择最大(id),国家

来自测试

group by country

I want only distinct values in one cloumn other columns can contain duplicate values,how do I achieve this

create table test
(
    Id int,
    Name varchar(max),
    Department varchar(max),
    Country varchar(max)
)
insert into test values (1,'B','IT','India')
insert into test values (2,'B','IT','US')
insert into test values (3,'C','HR','UK')
insert into test values (4,'D','HR','India')
insert into test values (5,'E','IT','US')
insert into test values (6,'F','IT','UK')
select * from test



I just want the non duplicate values in country column.
select id,country from test group by country FAILED
select id,country distinct from test FAILED

解决方案

The group by approach would work, but you need to decide what you want to see with the other columns. All columns not in the group by clause need to have some kind of aggregate function (max, min, avg etc)

an example of how to write the group by would be something like this:

select max(id), country
from test
group by country


这篇关于仅在一列中选择非重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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