PL-SQL: MM-DD dla podziałów i różnych kolumn
select sales_2021.sales_day_2021 as sales_day,
sales_2021.profit_2021,
sales_2022.profit_2022,
sales_2021.unit_count_2021,
sales_2022.unit_count_2022,
sales_2021.sales_2021,
sales_2022.sales_2022,
round((sales_2022.profit_2022 - sales_2021.profit_2021)*100/sales_2021.profit_2021, 2) as yoy_profit_pct,
round((sales_2022.unit_count_2022 - sales_2021.unit_count_2021)*100/sales_2021.unit_count_2021, 2) as yoy_inv_pct,
round((sales_2022.sales_2022 - sales_2021.sales_2021)*100/sales_2021.sales_2021, 2) as yoy_sales_pct
from
(select ltrim(TO_CHAR(TO_DATE(sold_dt,'dd/mm/yyyy'),'mm-dd'),'0') as sales_day_2022,
count(sold_id) as unit_count_2022,
sum(sold_price-usd_dealer_payable) as profit_2022,
sum(sold_price) as sales_2022
from inv.item_sold
where trunc(sold_dt) between to_date('01-JAN-22') and to_date('10-MAY-22')
and channel = 'EBAY2'
group by ltrim(TO_CHAR(TO_DATE(sold_dt,'dd/mm/yyyy'),'mm-dd'),'0')) sales_2022
join
(select ltrim(TO_CHAR(TO_DATE(sold_dt,'dd/mm/yyyy'),'mm-dd'),'0') as sales_day_2021,
count(sold_id) as unit_count_2021,
sum(sold_price-usd_dealer_payable) as profit_2021,
sum(sold_price) as sales_2021
from inv.item_sold
where trunc(sold_dt) between to_date('01-JAN-21') and to_date('10-MAY-21')
and channel = 'EBAY2'
group by ltrim(TO_CHAR(TO_DATE(sold_dt,'dd/mm/yyyy'),'mm-dd'),'0')) sales_2021
on sales_2021.sales_day_2021 = sales_2022.sales_day_2022
order by sales_2021.sales_day_2021 asc
Sumaia Parveen Shupti