|
Last change
on this file since 42da64d was 42da64d, checked in by Andrej <asumanovski@…>, 8 weeks ago |
|
Fixed auth issue
|
-
Property mode
set to
100644
|
|
File size:
796 bytes
|
| Line | |
|---|
| 1 | -- View: monthly income summary per user
|
|---|
| 2 | -- Shows total income per user per month and year
|
|---|
| 3 | CREATE OR REPLACE VIEW trekr.vw_finance_monthly_summary AS
|
|---|
| 4 | SELECT
|
|---|
| 5 | i.finance_user_id AS user_id,
|
|---|
| 6 | EXTRACT(YEAR FROM i.date)::int AS year,
|
|---|
| 7 | EXTRACT(MONTH FROM i.date)::int AS month,
|
|---|
| 8 | SUM(i.amount) AS total_income
|
|---|
| 9 | FROM trekr.incomes i
|
|---|
| 10 | GROUP BY i.finance_user_id, EXTRACT(YEAR FROM i.date), EXTRACT(MONTH FROM i.date);
|
|---|
| 11 |
|
|---|
| 12 | -- View: current month total money earned for each user
|
|---|
| 13 | CREATE OR REPLACE VIEW trekr.vw_finance_current_month AS
|
|---|
| 14 | SELECT
|
|---|
| 15 | f.user_id,
|
|---|
| 16 | COALESCE(SUM(i.amount), 0) AS total_earned_this_month
|
|---|
| 17 | FROM trekr.finance_users f
|
|---|
| 18 | LEFT JOIN trekr.incomes i
|
|---|
| 19 | ON i.finance_user_id = f.user_id
|
|---|
| 20 | AND date_trunc('month', i.date) = date_trunc('month', current_date)
|
|---|
| 21 | GROUP BY f.user_id;
|
|---|
| 22 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.