过滤重复数据最好在sql里面实现create table #
(用户ID int, 姓名 varchar(10), 年龄 int, 日期 DateTime )
insert into #
select 111, '张三', 26 2010-02-23 union all
select 222, '李四', 25 2010-03-13 union all
select 333, '王五', 30 2011-03-25 union all
select 111, '张三', 26 2011-07-07
方法:--当两条重,取日期大的一条
select * from t a
where not exists (select 1 from t where a.用户ID=用户ID a.姓名=姓名 and 日期>a.日期)
(用户ID int, 姓名 varchar(10), 年龄 int, 日期 DateTime )
insert into #
select 111, '张三', 26 2010-02-23 union all
select 222, '李四', 25 2010-03-13 union all
select 333, '王五', 30 2011-03-25 union all
select 111, '张三', 26 2011-07-07
方法:--当两条重,取日期大的一条
select * from t a
where not exists (select 1 from t where a.用户ID=用户ID a.姓名=姓名 and 日期>a.日期)
http://blog.csdn.net/senlin305/article/details/7641469