Search
 
SCRIPT & CODE EXAMPLE
 

SQL

PL-SQL: mm-dd for subqueries and different columns

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
Comment

PREVIOUS NEXT
Code Example
Sql :: sql table intermédiaire 
Sql :: sql insert into only auto id 
Sql :: ring get columns count in the query result using the odbc_colcount() 
Sql :: tsql For XML Path('), TYPE).value 
Sql :: sql server convert string list integers list 
Sql :: mostrar datos de tablas relacionadas mysql kjava 
Sql :: list of schema with sizes (relative and absolute) in a PostgreSQL database 
Sql :: select nth row in mysql 
Sql :: sp help text in postgresql 
Sql :: fill up postgres db 
Sql :: Update Query in SQL Server Table - NAYCode.com 
Sql :: sql convert 
Sql :: mysql Digital Ocean connection problems 
Sql :: how many columns can be used for creating index? 
Sql :: mysql order two columns 
Sql :: group by join columns per table 
Sql :: CREATE PROCEDURE CategoryInsert (IN c02 VARCHAR) BEGIN INSERT INTO Category(CategoryName) VALUES (c02); END; 
Sql :: sql constraint date greater than 
Sql :: difference between cross apply and inner join 
Sql :: can we compare two timestamps in mysql 
Sql :: difference table 
Sql :: Table aliases 
Sql :: mysql faster delete 
Sql :: mysql make date from 2 column 
Sql :: sql values that contains certain multiple ids 
Sql :: oracle execute package dblink 
Sql :: how to fetch highest score in minimum time using mysql 
Sql :: MySQL copy row with * 
Sql :: ora 00001 error catch plsql 
Sql :: what is union in sql 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =