zoukankan      html  css  js  c++  java
  • sql去除重复列(行)

    有重复数据主要有一下几种情况:
    
    1.存在两条完全相同的纪录
    
          这是最简单的一种情况,用关键字distinct就可以去掉
    
                       example: select distinct * from table(表名) where (条件)
    
    2.存在部分字段相同的纪录(有主键id即唯一键)
    
        如果是这种情况的话用distinct是过滤不了的,这就要用到主键id的唯一性特点及group by分组
    
                          example:
    
                                              select * from table where id in (select max(id) from table group by [去除重复的字段名列表,....])
    
    3.没有唯一键ID
    
        这种情况我觉得最复杂,目前我只会一种方法,有那位知道其他方法的可以留言,交流一下:
    
                          example:
    
                                          select identity(int1,1) as id,* into newtable(临时表) from table
    
                                             select * from newtable where id in (select max(id) from newtable group by [去除重复的字段名列表,....])
    
                                                drop table newtable
    
  • 相关阅读:
    jquery的each()详细介绍【转】
    牛客-小w的a=b问题
    HDU-6707-Shuffle Card(很数据结构的一道题)
    HDU-6672-Seq
    牛客-随机数
    牛客-小阳的贝壳
    HDU-4417-Super Mario
    牛客-Corn Fields
    HDU-2665-Kth number
    线段树模板
  • 原文地址:https://www.cnblogs.com/jkyweb/p/2043330.html
Copyright © 2011-2022 走看看