zoukankan      html  css  js  c++  java
  • 【sqlresolver】用sqlresolver给生产环境用到的SQL进行整形的效果陈列

    原文:

    select id,rank() over (order by id) as seq,sum(a) as sm,count(*) as cnt from emp

    整理后:

    select
        id,
        rank() over order by id  as seq,
        sum(a) as sm,
        count(*) as cnt
    from
        emp

    原文:

    select code,cname,ename,type from t_dict_data where type='A' and flag=1 and code='B'

    整理后:

    select
        code,
        cname,
        ename,
        type
    from
        t_dict_data
    where
        type = 'A' and 
        flag = 1 and 
        code = 'B'

    原文:

    select b.vdate visitDate,nvl(c.capacity,b.vcnt) capacity from
    (select to_char((trunc(sysdate-6)+(level-1)),'mm.dd') as vdate,0 as vcnt from dual connect by level<8) b
    left join
    (select to_char(a.create_time,'mm.dd') as visitDate,count(1) as capacity from
    (select create_time,user_id from dceapp.t_user_log where create_time>=trunc(sysdate-6)) a
    group by a.create_time
    ) c
    o b.vdate=c.visitDate
    order by b.vdate

    整形后:

    select
        b.vdate visitDate,
        nvl(c.capacity,b.vcnt) capacity
    from
        (
        select
            to_char((trunc(sysdate-6)+(level-1)),'mm.dd') as vdate,
            0asvcnt
        from
            dual
         connect by 
            level < 8) b left join 
        (
        select
            to_char(a.create_time,'mm.dd') as visitDate,
            count(1) as capacity
        from
            (
            select
                create_time,
                user_id
            from
                dceapp.t_user_log
            where
                create_time >= trunc(sysdate-6)) a
        group by
            a.create_time) c
    order by
        b.vdate

    原文:

    select trade_date,sum(posi_qty) posi_qty from (
    select dvttdi.trade_date,
    coalesce(dtcotdd.posi_qty,0) posi_qty
    from date_7 dvttdi
    left join dws.dws_t_cli_opt_trade_data_d dtcotdd
    on dvttdi.trade_date=dtcotdd.trade_date
    where dvttdi.rn<=7
    )

    整形后:

    select
        trade_date,
        sum(posi_qty) posi_qty
    from
        (
        select
            dvttdi.trade_date,
            coalesce(dtcotdd.posi_qty,0) posi_qty
        from
            date_7 dvttdi left join 
            dws.dws_t_cli_opt_trade_data_d dtcotdd
        on
            dvttdi.trade_date = dtcotdd.trade_date
        where
            dvttdi.rn <= 7)

    原文:

    select a.id,a.hostname,a.disksize,a.used,to_char(a.ctime,'hh24:mi:ss') as nctime
    from tmp a
    left join tmp b
    on a.ctime<b.ctime
    where b.ctime is NULL

    整形后:

    select
        a.id,
        a.hostname,
        a.disksize,
        a.used,
        to_char(a.ctime,'hh24:mi:ss') as nctime
    from
        tmp a left join 
        tmp b
    on
        a.ctime < b.ctime
    where
        b.ctime  is  NULL

    END

  • 相关阅读:
    gitblit安装使用
    谷歌AMP和百度MIP是什么鬼?
    微信小程序开发体验
    设计模式之策略模式
    【前端安全】JavaScript防XSS攻击
    【前端安全】JavaScript防流量劫持
    设计模式之“中间件模式”
    设计模式之Mixin模式
    设计模式之观察者模式
    设计模式之单例模式
  • 原文地址:https://www.cnblogs.com/heyang78/p/15478104.html
Copyright © 2011-2022 走看看