Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE MATERIALIZED VIEW staging.journal_2017_total AS
- (
- WITH
- company_1 AS (
- SELECT 'COMPANY 1' AS source, year, month_no, year_month, profit_center, revenue_class,
- cust_acc_name, billing_acc_name, sum(amount) AS amount
- FROM staging.journal_company_1
- GROUP BY year, month_no, year_month, profit_center, revenue_class,
- cust_acc_name, billing_acc_name
- ),
- company_2 AS (
- SELECT 'COMPANY 2' as source, year, month_no, year_month, profit_center, revenue_class,
- cust_acc_name, billing_acc_name, sum(amount) AS amount
- FROM staging.journal_company_2
- GROUP BY year, month_no, year_month, profit_center, revenue_class,
- cust_acc_name, billing_acc_name
- )
- SELECT source, year, month_no, year_month, profit_center, revenue_class,
- cust_acc_name, billing_acc_name, amount
- FROM company_1
- UNION ALL
- SELECT source, year, month_no, year_month, profit_center, revenue_class,
- cust_acc_name, billing_acc_name, amount
- FROM company_2
- )
Add Comment
Please, Sign In to add comment