• 找出两个异构数据库的差异(找出其中的缺失记录)


    -- 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'
    ;
  • 相关阅读:
    最短路径问题大总结(提纲)
    单源最短路——Bellman-Ford算法
    多源最短路——Floyd算法
    Bracket Sequences Concatenation Problem括号序列拼接问题(栈+map+思维)
    数位DP
    C++ string中的find()函数
    Planning The Expedition(暴力枚举+map迭代器)
    8月5号团队赛补题
    8月3号水题走一波-个人赛五
    Walking Between Houses(贪心+思维)
  • 原文地址:https://www.cnblogs.com/chenzechao/p/12609187.html
Copyright © 2020-2023  润新知