*(00)*

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::


--重复ID的记录,只显示其中1条

--生成原始表
select * into #tempTable from (
select '1' as id ,'a' as name
union all
select '1' as id ,'b' as name
union all
select '2' as id ,'c' as name
union all
select '2' as id ,'d' as name ) a

--查询原始表
select * from #tempTable

--增加序号列
select ROW_NUMBER() OVER (ORDER BY id) AS xh ,* into #tempTableXh from #tempTable

--最终查询
select * from #tempTableXh where xh in (select MIN(xh) from #tempTableXh group by id)

--删除临时表
drop table #tempTable
drop table #tempTableXh

posted on 2016-01-08 14:54  *(00)*  阅读(197)  评论(0编辑  收藏  举报