-- // 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