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

请输入您要查询的范文:

 

标题 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/20 3:45:44