㈠ SQL语句,如何把搜寻出来的数据中某个字段重复的数据去除
--不知道是不是我理解的,如果不是请追问
select*,A+casewhenB=ATHEN''ELSEBEND
+CASEWHENC=AORC=BTHEN''ELSECEND
+CASEWHEND=AORD=BORD=CTHEN''ELSEDENDfrom表名
㈡ excel 如何筛选出有相同字段的数据
将光标放在姓名列的任意单元格,点击排序就可以了。相同的姓名就排在一起了,然后按需要进行下一步处理。
㈢ MySQL过滤部分字段重复的数据
select
distinct可以去掉重复记录。
disctinct将重复的记录忽略,但它忽略的是完全一致的回重复记录,答而不是其中某个字段重复的记录,或者说,distinct查询一个字段时好使,多个字段就不好使。
所以用聚合函数和group
by实现
注意:group
by只能跟聚合函数搭配使用
例表
ID
username
password
TRDESC
1
A
abcdef
QR
2
A
abcdef
W34
3
A
bbbbbb
AD
4
B
aaaaaa
asdf
查询username和password组合起来的条件不能重复的查询结果(这个都能重复,不能不说这是个烂摊子)
select
*
from
mytable
where
ID
in(select
max(ID)
from
mytable
group
by
username,password)
当username和password重复时,取ID最小的记录:
select
*
from
mytable
where
ID
in(select
min(ID)
from
mytable
a
group
by
username,password)
㈣ excel 过滤某列的重复数据项
单用COUNTIF()是做不到的。
如果你想做出个下拉列表,可以通过有效性来做。
我的思路是这样的:
先用
=INDEX($A:$A,SMALL(IF(MATCH($A$1:$A$20,$A:$A,0)=ROW($1:$20),ROW($1:$20),21),ROW(1:1)))
(注意:上面是数组公式,要用Ctrl + Shift + Enter三键组合来确认)
在B列生成一个去除A列重复数据的列
再在C1单元格内设置有效性,有效性设置成“系列”,“来源”选B1到B50(你说的是50个不重复的,可根据实际不重复的人名来设定“来源”)
确认后C1里的下拉列表里就是这1000个人名中不重复的50个人名了。
㈤ sql查找某一字段相同的所有数据
1、在我们的电脑上打开数据库,这里新建一张含有重复数据的user表做示例。
㈥ sql 如何过滤重复记录
问题背景
在一个多表查询的sql中正常情况下产生的数据都是唯一的,但因为数据库中存在错误(某张表中存在相同的外键ID)导致我这边查询出来的数据就会有重复的问题
下面结果集中UserID:15834存在多个
参考:
MSDN: OVER 子句 (Transact-SQL)
stackoverflow sql query distinct with Row_Number
SQL Trick: row_number() is to SELECT what dense_rank() is to SELECT DISTINCT
㈦ 如何在Excel里对某一个字段筛选出具有相同值的记录
筛选法: 假定要在A1-A20的区域内筛选出男性职工[假定这块区域放性别]
步骤:一、列明条件,比如在A22空格里输入"性别"(注意这里要输你放性别数据的字段名)
二、在A23单元格内输入查找的值(注意只能是放在字段名下面,因为字段名包含数据嘛)
三、使用命令,数据-筛选-高级筛选,其中的数据区域为本例[A1:A20]条件区域为本例[A22:A23]
四、完成。
另外一种解答方法
函数法:因为你的目的只是找到相同列里相同值的记录.建议使用函数:countif (条件统计)
函数语法如下:
=countif(range,criteria)
其中range为需要计算的区域
criteria为指定的条件,
举例:
比如我有一个性别数据是从A1-A20 假若我想找其中性别为"男"的值,用函数解答为: =countif(a1:a20,"男")便可找出指定的条件[男]的记录
㈧ sql查询中如何去除某个字段重复的数据
我一般用这个:
假设怀疑重复的字段名为SeriNo,
select
*
from
[tablename]
group
by
SeriNo
having
count(SeriNo)<>1
㈨ sql 过滤掉多字段重复的记录
-按某一字段分组取最大(小)值所在行的数据
--(爱新觉罗.毓华(十八年风雨,守得冰山雪莲花开) 2007-10-23于浙江杭州)
/*
数据如下:
name val(成绩) memo(科目)
a 2 a2(a的第二个值)
a 1 a1--a的第一个值
a 3 a3:a的第三个值
b 1 b1--b的第一个值
b 3 b3:b的第三个值
b 2 b2b2b2b2
b 4 b4b4
b 5 b5b5b5b5b5
*/
--创建表并插入数据:
create table tb(name varchar(10),val int,memo varchar(20))
insert into tb values('a', 2, 'a2(a的第二个值)')
insert into tb values('a', 1, 'a1--a的第一个值')
insert into tb values('a', 3, 'a3:a的第三个值')
insert into tb values('b', 1, 'b1--b的第一个值')
insert into tb values('b', 3, 'b3:b的第三个值')
insert into tb values('b', 2, 'b2b2b2b2')
insert into tb values('b', 4, 'b4b4')
insert into tb values('b', 5, 'b5b5b5b5b5')
go
--一、按name分组取val最大的值所在行的数据。
--方法1:
select a.* from tb a where val = (select max(val) from tb where name = a.name) order by a.name
--方法2:
select a.* from tb a where not exists(select 1 from tb where name = a.name and val > a.val)
--方法3:
select a.* from tb a,(select name,max(val) val from tb group by name) b where a.name = b.name and a.val = b.val order by a.name
--方法4:
select a.* from tb a inner join (select name , max(val) val from tb group by name) b on a.name = b.name and a.val = b.val order by a.name
--方法5
select a.* from tb a where 1 > (select count(*) from tb where name = a.name and val > a.val ) order by a.name
/*
name val memo
---------- ----------- --------------------
a 3 a3:a的第三个值
b 5 b5b5b5b5b5
*/
--二、按name分组取val最小的值所在行的数据。
--方法1:
select a.* from tb a where val = (select min(val) from tb where name = a.name) order by a.name
--方法2:
select a.* from tb a where not exists(select 1 from tb where name = a.name and val < a.val)
--方法3:
select a.* from tb a,(select name,min(val) val from tb group by name) b where a.name = b.name and a.val = b.val order by a.name
--方法4:
select a.* from tb a inner join (select name , min(val) val from tb group by name) b on a.name = b.name and a.val = b.val order by a.name
--方法5
select a.* from tb a where 1 > (select count(*) from tb where name = a.name and val < a.val) order by a.name
/*
name val memo
---------- ----------- --------------------
a 1 a1--a的第一个值
b 1 b1--b的第一个值
*/
--三、按name分组取第一次出现的行所在的数据。
select a.* from tb a where val = (select top 1 val from tb where name = a.name) order by a.name
/*
name val memo
---------- ----------- --------------------
a 2 a2(a的第二个值)
b 1 b1--b的第一个值
*/
--四、按name分组随机取一条数据。
select a.* from tb a where val = (select top 1 val from tb where name = a.name order by newid()) order by a.name
/*
name val memo
---------- ----------- --------------------
a 1 a1--a的第一个值
b 5 b5b5b5b5b5
*/
--五、按name分组取最小的两个(N个)val
select a.* from tb a where 2 > (select count(*) from tb where name = a.name and val < a.val ) order by a.name,a.val
select a.* from tb a where val in (select top 2 val from tb where name=a.name order by val) order by a.name,a.val
select a.* from tb a where exists (select count(*) from tb where name = a.name and val < a.val having Count(*) < 2) order by a.name,a.val
/*
name val memo
---------- ----------- --------------------
a 1 a1--a的第一个值
a 2 a2(a的第二个值)
b 1 b1--b的第一个值
b 2 b2b2b2b2
*/
--六、按name分组取最大的两个(N个)val
select a.* from tb a where 2 > (select count(*) from tb where name = a.name and val > a.val ) order by a.name,a.val
select a.* from tb a where val in (select top 2 val from tb where name=a.name order by val desc) order by a.name,a.val
select a.* from tb a where exists (select count(*) from tb where name = a.name and val > a.val having Count(*) < 2) order by a.name , a.val
/*
name val memo
---------- ----------- --------------------
a 2 a2(a的第二个值)
a 3 a3:a的第三个值
b 4 b4b4
b 5 b5b5b5b5b5
*/
--七,如果整行数据有重复,所有的列都相同。
/*
数据如下:
name val memo
a 2 a2(a的第二个值)
a 1 a1--a的第一个值
a 1 a1--a的第一个值
a 3 a3:a的第三个值
a 3 a3:a的第三个值
b 1 b1--b的第一个值
b 3 b3:b的第三个值
b 2 b2b2b2b2
b 4 b4b4
b 5 b5b5b5b5b5
*/
--在sql server 2000中只能用一个临时表来解决,生成一个自增列,先对val取最大或最小,然后再通过自增列来取数据。
--创建表并插入数据:
create table tb(name varchar(10),val int,memo varchar(20))
insert into tb values('a', 2, 'a2(a的第二个值)')
insert into tb values('a', 1, 'a1--a的第一个值')
insert into tb values('a', 1, 'a1--a的第一个值')
insert into tb values('a', 3, 'a3:a的第三个值')
insert into tb values('a', 3, 'a3:a的第三个值')
insert into tb values('b', 1, 'b1--b的第一个值')
insert into tb values('b', 3, 'b3:b的第三个值')
insert into tb values('b', 2, 'b2b2b2b2')
insert into tb values('b', 4, 'b4b4')
insert into tb values('b', 5, 'b5b5b5b5b5')
go
select * , px = identity(int,1,1) into tmp from tb
select m.name,m.val,m.memo from
(
select t.* from tmp t where val = (select min(val) from tmp where name = t.name)
) m where px = (select min(px) from
(
select t.* from tmp t where val = (select min(val) from tmp where name = t.name)
) n where n.name = m.name)
drop table tb,tmp
/*
name val memo
---------- ----------- --------------------
a 1 a1--a的第一个值
b 1 b1--b的第一个值
(2 行受影响)
*/
--在sql server 2005中可以使用row_number函数,不需要使用临时表。
--创建表并插入数据:
create table tb(name varchar(10),val int,memo varchar(20))
insert into tb values('a', 2, 'a2(a的第二个值)')
insert into tb values('a', 1, 'a1--a的第一个值')
insert into tb values('a', 1, 'a1--a的第一个值')
insert into tb values('a', 3, 'a3:a的第三个值')
insert into tb values('a', 3, 'a3:a的第三个值')
insert into tb values('b', 1, 'b1--b的第一个值')
insert into tb values('b', 3, 'b3:b的第三个值')
insert into tb values('b', 2, 'b2b2b2b2')
insert into tb values('b', 4, 'b4b4')
insert into tb values('b', 5, 'b5b5b5b5b5')
go
select m.name,m.val,m.memo from
(
select * , px = row_number() over(order by name , val) from tb
) m where px = (select min(px) from
(
select * , px = row_number() over(order by name , val) from tb
) n where n.name = m.name)
drop table tb
/*
name val memo
---------- ----------- --------------------
a 1 a1--a的第一个值
b 1 b1--b的第一个值
(2 行受影响)
*/
㈩ sql语句查询过滤重复数据
1、查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断
复制代码代码如下:
select * from people
where peopleId in (select peopleId from people group by peopleId having count
(peopleId) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断,只留有rowid最小的记录
复制代码代码如下:
delete from people
where peopleId in (select peopleId from people group by peopleId having count
(peopleId) > 1)
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId
)>1)