zoukankan      html  css  js  c++  java
  • 重复ID的记录,只显示其中1条


    --重复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

  • 相关阅读:
    git命令总结
    Junit
    zookeeper--概述
    NIO与Socket
    分区分表
    ThreadLocal
    垃圾收集器
    垃圾收集算法
    主从复制
    Redis--集群
  • 原文地址:https://www.cnblogs.com/zouhao/p/5113246.html
Copyright © 2011-2022 走看看