网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 SQL Server查询语句过滤重复的数据
内容  
    情况一:表中存在完全重复的的数据,即所有字段内容都是相同的
    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.日期)
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/26 7:36:47