Skip to content

Commit 3ce575b

Browse files
committed
4031: Adds revenue summary view
1 parent 225ae86 commit 3ce575b

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

database/changelog/changelog-views/fiscal-year-summary-views.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ databaseChangeLog:
1515
runOnChange: true
1616
changes:
1717
- sqlFile:
18-
path: src/views/max_fy_month_by_dataset_v.sql
18+
path: src/views/max_fy_month_by_dataset_v.sql
19+
20+
- changeSet:
21+
id: fy-revenue-summary-view
22+
author: Jeff Schwartz
23+
runOnChange: true
24+
changes:
25+
- sqlFile:
26+
path: src/views/fy_revenue_summary_v.sql
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
CREATE OR REPLACE VIEW fy_revenue_summary_v AS
2+
SELECT SUM(revenue) revenue,
3+
'current' fy
4+
FROM revenue r,
5+
period pe
6+
WHERE pe.period_id = r.period_id
7+
AND pe.period = 'Monthly'
8+
AND pe.fiscal_year = (
9+
SELECT max(fiscal_year)
10+
FROM period pe2
11+
WHERE exists (
12+
SELECT 1
13+
FROM revenue
14+
WHERE period_id = pe2.period_id
15+
)
16+
)
17+
GROUP BY fy
18+
UNION
19+
SELECT SUM(revenue) revenue,
20+
'previous' fy
21+
FROM revenue r,
22+
period pe
23+
WHERE pe.period_id = r.period_id
24+
AND pe.period = 'Monthly'
25+
AND pe.fiscal_year = (
26+
SELECT max(fiscal_year) - 1
27+
FROM period pe2
28+
WHERE exists (
29+
SELECT 1
30+
FROM revenue
31+
WHERE period_id = pe2.period_id
32+
)
33+
)
34+
AND pe.fiscal_month <= (
35+
SELECT max(fiscal_month)
36+
FROM period pe2
37+
WHERE fiscal_year = (
38+
SELECT max(fiscal_year)
39+
FROM period pe3
40+
WHERE exists (
41+
SELECT 1
42+
FROM production
43+
WHERE period_id = pe2.period_id
44+
)
45+
)
46+
)
47+
GROUP BY fy;

0 commit comments

Comments
 (0)