zoukankan      html  css  js  c++  java
  • 找出两个异构数据库的差异(找出其中的缺失记录)

    -- oracle
    select
         substr(md5(key_id),1,1) as flag
        ,count(1)             as cnt
    from (
        select 1  as key_id union all 
        select 2  as key_id union all 
        select 3  as key_id union all 
        select 4  as key_id union all 
        select 5  as key_id union all 
        select 6  as key_id union all 
        select 7  as key_id union all 
        select 8  as key_id union all 
        select 9  as key_id union all 
        select 10 as key_id
    ) t1
    group by 
        substr(md5(key_id),1,1)
    ;
    +------+-----+
    | flag | cnt |
    +------+-----+
    | 1    |   1 |
    | 4    |   1 |
    | 8    |   1 |
    | a    |   1 |
    | c    |   3 |
    | d    |   1 |
    | e    |   2 |
    +------+-----+
    
    -- hive
    select
         substr(md5(key_id),1,1) as flag
        ,count(1)             as cnt
    from (
        select 1  as key_id union all 
        select 2  as key_id union all 
        select 3  as key_id union all 
        select 4  as key_id union all 
        select 5  as key_id union all 
        select 6  as key_id union all 
        select 7  as key_id union all 
        select 9  as key_id union all 
        select 10  as key_id
    ) t1
    group by 
        substr(md5(key_id),1,1)
    ;
    +------+-----+
    | flag | cnt |
    +------+-----+
    | 1    |   1 |
    | 4    |   1 |
    | 8    |   1 |
    | a    |   1 |
    | c    |   2 |
    | d    |   1 |
    | e    |   2 |
    +------+-----+
    
    -- 经过比对,flag c有差异
    -- oracle
    select
         substr(md5(key_id),1,2) as flag
        ,count(1)             as cnt
    from (
        select 1  as key_id union all 
        select 2  as key_id union all 
        select 3  as key_id union all 
        select 4  as key_id union all 
        select 5  as key_id union all 
        select 6  as key_id union all 
        select 7  as key_id union all 
        select 8  as key_id union all 
        select 9  as key_id union all 
        select 10 as key_id
    ) t1
    where substr(md5(key_id),1,1) = 'c'
    group by 
        substr(md5(key_id),1,2)
    ;
    +------+-----+
    | flag | cnt |
    +------+-----+
    | c4   |   1 |
    | c8   |   1 |
    | c9   |   1 |
    +------+-----+
    
    -- hive
    select
         substr(md5(key_id),1,2) as flag
        ,count(1)             as cnt
    from (
        select 1  as key_id union all 
        select 2  as key_id union all 
        select 3  as key_id union all 
        select 4  as key_id union all 
        select 5  as key_id union all 
        select 6  as key_id union all 
        select 7  as key_id union all 
        select 9  as key_id union all 
        select 10 as key_id
    ) t1
    where substr(md5(key_id),1,1) = 'c'
    group by 
        substr(md5(key_id),1,2)
    ;
    +------+-----+
    | flag | cnt |
    +------+-----+
    | c4   |   1 |
    | c8   |   1 |
    +------+-----+
    
    -- 经过比对,flag c9有差异
    -- oracle
    select t1.*
    from (
        select 1  as key_id union all 
        select 2  as key_id union all 
        select 3  as key_id union all 
        select 4  as key_id union all 
        select 5  as key_id union all 
        select 6  as key_id union all 
        select 7  as key_id union all 
        select 8  as key_id union all 
        select 9  as key_id union all 
        select 10 as key_id
    ) t1
    where substr(md5(key_id),1,2) = 'c9'
    ;
  • 相关阅读:
    图像有用区域--------深搜和广搜的第一次二选一
    24Pointgame-----24点游戏
    CAP定理和BASE理论
    并查集
    七桥问题和一笔画
    组合数问题--------一种新的 搜索 思路
    最少换乘 之简化版
    吝啬的国度 ---用vector 来构图
    WGZX:javaScript 学习心得--1
    eclipse Maven -->web project
  • 原文地址:https://www.cnblogs.com/chenzechao/p/12609187.html
Copyright © 2011-2022 走看看