source: db-scripts/views/finance_allocations_view.sql@ c0086c0

Last change on this file since c0086c0 was 42da64d, checked in by Andrej <asumanovski@…>, 8 weeks ago

Fixed auth issue

  • Property mode set to 100644
File size: 909 bytes
Line 
1-- View: calculate allocation amounts per finance category for the current month
2CREATE OR REPLACE VIEW trekr.vw_finance_allocations_current_month AS
3SELECT
4 f.user_id,
5 fm.total_earned_this_month,
6 f.spending_budget,
7 f.saving_budget,
8 f.investing_budget,
9 f.donation_budget,
10 f.credit,
11 ROUND((COALESCE(f.spending_budget,0) / 100.0) * fm.total_earned_this_month, 2) AS spending_amount,
12 ROUND((COALESCE(f.saving_budget,0) / 100.0) * fm.total_earned_this_month, 2) AS saving_amount,
13 ROUND((COALESCE(f.investing_budget,0) / 100.0) * fm.total_earned_this_month, 2) AS investing_amount,
14 ROUND((COALESCE(f.donation_budget,0) / 100.0) * fm.total_earned_this_month, 2) AS donation_amount,
15 ROUND((COALESCE(f.credit,0) / 100.0) * fm.total_earned_this_month, 2) AS credit_amount
16FROM trekr.finance_users f
17LEFT JOIN trekr.vw_finance_current_month fm ON fm.user_id = f.user_id;
18
Note: See TracBrowser for help on using the repository browser.