sql dld_monthly_trans_api代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql dld_monthly_trans_api代码相关的知识,希望对你有一定的参考价值。

-- // VOLUMN // --


select 
    sum(volum_2017) as volume_2017,
    sum(volum_2018) as volume_2018,
    h,
    area,
    ROUND (
            ( ( sum(volum_2018)   -  sum(volum_2017))  /  (case sum(volum_2017) when 0 then 1 else sum(volum_2017) end )   ) * 100
    ,1) CHANGE
from (
    select
    sum (transaction_count) as volum_2017, 
    0 volum_2018,
    (case when to_char(transaction_date,'q') <= 2 then 'h1' else 'h2' end) as h,
    name_en as area

    from 
    dld_monthly_trans_api
    where extract (year from transaction_date ) = 2017
    group by  to_char(transaction_date,'q'),name_en

    union all

    select 
    0 as volum_2017,
    sum (transaction_count) as volum_2018,
    (case when to_char(transaction_date,'q') <= 2 then 'h1' else 'h2' end) as h,
    name_en as area
    from 
    dld_monthly_trans_api
    where extract (year from transaction_date ) = 2018
    group by  to_char(transaction_date,'q'),name_en
)
where lower(h) = 'h1'
group by h,area



 --// Value //--



select 
    sum(worth_2017) as worth_2017,
    sum(worth_2018) as worth_2018,
    h,
    area,
    ROUND (
            ( ( sum(worth_2018)   -  sum(worth_2017))  / (case sum(worth_2017) when 0 then 1 else sum(worth_2017) end)    ) * 100

    ,1) CHANGE
from (
    select
    sum (worth) as worth_2017,
    0 as worth_2018,
    (case when to_char(transaction_date,'q') <= 2 then 'h1' else 'h2' end) as h,
    name_en as area

    from 
    dld_monthly_trans_api
    where extract (year from transaction_date ) = 2017
    group by  to_char(transaction_date,'q'),name_en

    union all

    select 
    0 as worth_2017,
    sum (worth) as worth_2018,
    (case when to_char(transaction_date,'q') <= 2 then 'h1' else 'h2' end) as h,
    name_en as area
    from 
    dld_monthly_trans_api
    where extract (year from transaction_date ) = 2018
    group by  to_char(transaction_date,'q'),name_en
)
where lower(h) = 'h1'
group by h,area

以上是关于sql dld_monthly_trans_api代码的主要内容,如果未能解决你的问题,请参考以下文章

sql 2008和sql 2012的区别

sql [sql技巧]一些sql技巧#sql

sql 2008 r2 在sql 2008上兼容么

SQL基础

有大神知道,sql server 中如何批量执行sql语句吗?

pl sql developer怎么执行sql