SQL Server查询语句过滤重复的数据

SQL Server查询语句过滤重复的数据

2023年6月27日发(作者:)

情况一:表中存在完全重复的的数据,即所有字段内容都是相同的

create table #

(用户ID int, 姓名 varchar(10), 年龄 int )

insert into #

select 111, '张三', 26 union all

select 222, '李四', 25 union all

select 333, '王五', 30 union all

select 111, '张三', 26

方法: select distinct * from #

情况2:表中存在部分数据重复的字段,即 重复数据中至少有一个字段不重复create

table #(用户ID int, 姓名 varchar(10), 年龄 int, 日期 DateTime )insert into #select 111, '张三', 26 2010-02-23 union allselect 222, '李四', 25 2010-03-13 union allselect 333, '王五', 30

2011-03-25 union allselect 111, '张三', 26 2011-07-07方法:--当两条重,取日期大的一条

select * from t a

where not exists (select 1 from t where a.用户ID=用户ID a.姓名=姓名 and 日期>a.日期)

更多信息请查看IT技术专栏

发布者:admin,转转请注明出处:http://www.yc00.com/news/1687817896a47773.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信