国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

oracle數(shù)據(jù)庫(kù)去除重復(fù)數(shù)據(jù)常用的方法總結(jié)

瀏覽:91日期:2023-03-12 15:25:05
目錄
  • 創(chuàng)建測(cè)試數(shù)據(jù)
  • 針對(duì)指定列,查出去重后的結(jié)果集
    • distinct
    • row_number()
  • 針對(duì)指定列,查出所有重復(fù)的行
    • count having
    • count over
  • 刪除所有重復(fù)的行
    • 刪除重復(fù)數(shù)據(jù)并保留一條
      • 分析函數(shù)法
      • group by
    • 總結(jié)

      創(chuàng)建測(cè)試數(shù)據(jù)

      create table nayi224_180824(col_1 varchar2(10), col_2 varchar2(10), col_3 varchar2(10));
      insert into nayi224_180824
      select 1, 2, 3 from dual union all
      select 1, 2, 3 from dual union all
      select 5, 2, 3 from dual union all
      select 10, 20, 30 from dual ;
      commit;
      select*from nayi224_180824;
      COL_1COL_2COL_3123123523102030

      針對(duì)指定列,查出去重后的結(jié)果集

      distinct

      select distinct t1.* from nayi224_180824 t1;
      
      COL_1COL_2COL_3102030123523

      方法局限性很大,因?yàn)樗荒軐?duì)全部查詢的列做去重。如果我想對(duì)col_2,col3去重,那我的結(jié)果集中就只能有col_2,col_3列,而不能有col_1列。

      select distinct t1.col_2, col_3 from nayi224_180824 t1
      
      COL_2COL_3232030

      不過(guò)它也是最簡(jiǎn)單易懂的寫法。

      row_number()

      select *
        from (select t1.*,
             row_number() over(partition by t1.col_2, t1.col_3 order by 1) rn
        from nayi224_180824 t1) t1
       where t1.rn = 1
      ;
      
      COL_1COL_2COL_3RN12311020301

      寫法上要麻煩不少,但是有更大的靈活性。

      針對(duì)指定列,查出所有重復(fù)的行

      count having

      select *
        from nayi224_180824 t
       where (t.col_2, t.col_3) in (select t1.col_2, t1.col_3
      from nayi224_180824 t1
             group by t1.col_2, t1.col_3
            having count(1) > 1)
      
      COL_1COL_2COL_3123123523

      要查兩次表,效率會(huì)比較低。不推薦。

      count over

      select *
        from (select t1.*,
             count(1) over(partition by t1.col_2, t1.col_3) rn
        from nayi224_180824 t1) t1
       where t1.rn > 1
      ;
      
      COL_1COL_2COL_3RN123312335233

      只需要查一次表,推薦。

      刪除所有重復(fù)的行

      delete from nayi224_180824 t
       where t.rowid in (
         select rid
           from (select t1.rowid rid,
         count(1) over(partition by t1.col_2, t1.col_3) rn
            from nayi224_180824 t1) t1
          where t1.rn > 1);
      

      就是上面的語(yǔ)句稍作修改。

      刪除重復(fù)數(shù)據(jù)并保留一條

      分析函數(shù)法

      delete from nayi224_180824 t
       where t.rowid in (select rid
           from (select t1.rowid rid,
        row_number() over(partition by t1.col_2, t1.col_3 order by 1) rn
           from nayi224_180824 t1) t1
          where t1.rn > 1);
      

      擁有分析函數(shù)一貫的靈活性高的特點(diǎn)。可以為所欲為的分組,并通過(guò)改變orderby從句來(lái)達(dá)到像”保留最大id“這樣的要求。

      group by

      delete from nayi224_180824 t
       where t.rowid not in
             (select max(rowid) from nayi224_180824 t1 group by t1.col_2, t1.col_3);
      

      犧牲了一部分靈活性,換來(lái)了更高的效率。

      總結(jié)

      到此這篇關(guān)于oracle數(shù)據(jù)庫(kù)去除重復(fù)數(shù)據(jù)常用的文章就介紹到這了,更多相關(guān)oracle去除重復(fù)數(shù)據(jù)內(nèi)容請(qǐng)搜索以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持!

      標(biāo)簽: Oracle
      主站蜘蛛池模板: 免费一级在线观看 | 国产成人资源 | 亚洲一区二区中文字幕 | 欧美在线香蕉在线现视频 | 精品国产无限资源免费观看 | 久久精品国产一区二区三区日韩 | 秋霞手机入口二日韩区 | 国产精品一区二区手机在线观看 | 日韩成人一级 | 在线观看一区二区三区四区 | 91久久亚洲精品国产一区二区 | 日韩中文字幕视频 | 国产精品久久久久久久久久久搜索 | 国产精品性视频免费播放 | 日韩理论视频 | 澳门一级毛片手机在线看 | 2022久久免费精品国产72精品 | 美女张开腿让男人桶的 视频 | 失禁h啪肉尿出来高h健身房 | 久久精品视频免费观看 | 日本欧美中文 | 国产精品系列在线 | 欧美日韩国产58香蕉在线视频 | 视频在线一区 | 日韩 欧美 中文 亚洲 高清 在线 | 九九久久国产精品 | 看片网站在线 | 亚洲精品天堂在线观看 | 自拍 亚洲 欧美 | 国产在线精品一区免费香蕉 | aaaaaa精品视频在线观看 | 国产成年人视频 | 欧美线在线精品观看视频 | 欧美深夜影院 | 国产一区二区三区不卡免费观看 | 免费a级毛片大学生免费观看 | 国产精品特级毛片一区二区三区 | 亚洲男人天堂2017 | 91视频国产91久久久 | 欧美一级级a在线观看 | 久久精品国产免费看久久精品 |