Guest User

Untitled

a guest
Nov 18th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. CREATE MATERIALIZED VIEW staging.journal_2017_total AS
  2. (
  3. WITH
  4. company_1 AS (
  5. SELECT 'COMPANY 1' AS source, year, month_no, year_month, profit_center, revenue_class,
  6. cust_acc_name, billing_acc_name, sum(amount) AS amount
  7. FROM staging.journal_company_1
  8. GROUP BY year, month_no, year_month, profit_center, revenue_class,
  9. cust_acc_name, billing_acc_name
  10. ),
  11.  
  12. company_2 AS (
  13. SELECT 'COMPANY 2' as source, year, month_no, year_month, profit_center, revenue_class,
  14. cust_acc_name, billing_acc_name, sum(amount) AS amount
  15. FROM staging.journal_company_2
  16. GROUP BY year, month_no, year_month, profit_center, revenue_class,
  17. cust_acc_name, billing_acc_name
  18. )
  19.  
  20. SELECT source, year, month_no, year_month, profit_center, revenue_class,
  21. cust_acc_name, billing_acc_name, amount
  22. FROM company_1
  23.  
  24. UNION ALL
  25.  
  26. SELECT source, year, month_no, year_month, profit_center, revenue_class,
  27. cust_acc_name, billing_acc_name, amount
  28. FROM company_2
  29. )
Add Comment
Please, Sign In to add comment