www.7671.net > 数据库重复数据只取一次

数据库重复数据只取一次

1 selectdistinct(籍贯) from学生信息 --去除重复记录 distinct(不相同).查询去除籍贯重复的信息

select distinct 字段名,字段名from 表名 where 条件

既然数据都重复,就时间不同,那就取max(时间)就行了吧select 重复数据的列名1,重复数据的列名2,.,max(时间列) from table group by 重复数据的列名1,重复数据的列名2,.

select * from test where name=" 名称"; select count(*) from test where name="名称 ";select * from test where name="名称" order by price desc;

在select 后面加 distinct取消重复select distinct info.dev_id,info.boot_time,info.off_time,cmd.CMD from dbo.TT_Dev_Command cmd,dbo.TT_Dev_Info info where info.dev_mac like '%'+ @mac +'%' and cmd.dev_id = (select dev_id from TT_Dev_Info where dev_mac like '%'+@mac+'%' group by Date)

select * from table ### where not exists ( select * from table ### where # = # and ## < ##) 在使用mysql时,有时需要查询出某个字段不重复的记录,虽然mysql提供 有distinct这个关键字来过滤掉多余的重复记录只保留一条,但往往只用

select username,count(*) from a where datepart(month,timestr)=12 group by username having count(*) = 1 order by 2

设表为table1,字段为id int,name varchar(18)这样可以保留同名(重复的name)中最小id的记录delete table1 where exists(select 1 from table1 as a where a.id>table1.id and a.name=table1.name)

select distinct 列名 from 表名

SELECT DISTINCT *FROM 表mainWHERE NOT EXISTS ( SELECT * FROM 表sub WHERE main.产品 = sub.产品 AND main.时间 < sub.时间 )

友情链接:ddng.net | lyhk.net | ntjm.net | yydg.net | gmcy.net | 网站地图

All rights reserved Powered by www.7671.net

copyright ©right 2010-2021。
www.7671.net内容来自网络,如有侵犯请联系客服。zhit325@qq.com