
SQL查询时如何去掉重复记录后保留最新的记
1个回答
展开全部
测试数据:
if object_id('tempdb.dbo.#') is not null drop table #
create table #(姓名 varchar(8), 日期 datetime)
insert into #
select '张三', '2009-01-01' union all
select '张三', '2010-10-10' union all
select '李四', '2010-1-10'
select * from # t where not exists (select 1 from # where 姓名=t.姓名 and 日期>t.日期)
if object_id('tempdb.dbo.#') is not null drop table #
create table #(姓名 varchar(8), 日期 datetime)
insert into #
select '张三', '2009-01-01' union all
select '张三', '2010-10-10' union all
select '李四', '2010-1-10'
select * from # t where not exists (select 1 from # where 姓名=t.姓名 and 日期>t.日期)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |