4
4
5
5
-- Export Query 1
6
6
-- Get all cost_recovery rows with the latest subscription names
7
+ -- Outputs sheet cost-recovery_YY-YY_qN
7
8
select cr." id" , finance_id, " month" , finance_code, sd .display_name , cr .subscription_id , amount
8
9
from accounting .cost_recovery cr
9
10
join (
@@ -14,16 +15,18 @@ join (
14
15
on latest_names .subscription_id = cr .subscription_id
15
16
join accounting .subscription_details sd
16
17
on sd .id = latest_names .max_id
17
- where cr .month >= ' 2022-04-00' ; -- the first day of the recovery period
18
+ where cr .month >= ' 2024-04-00' -- the first day of the recovery period
19
+ and cr .month < ' 2024-07-00' ; -- one day after the recovery-period end date, typically three months after the start
18
20
19
21
20
22
-- Export Query 2
21
23
-- Get a breakdown of each subscription's usage
24
+ -- Outputs usage_YY-YY_qN
22
25
select
23
26
u .subscription_id ,
24
27
display_name,
25
28
-- product,
26
- date_trunc(' month' , u." date" ) as the_date ,
29
+ date ( date_trunc(' month' , u." date" )) as date_trunc ,
27
30
sum (total_cost) as total_cost,
28
31
sum (amortised_cost) as amortised_cost,
29
32
sum (cost) as cost
37
40
on latest_names .subscription_id = u .subscription_id
38
41
join accounting .subscription_details sd
39
42
on sd .id = latest_names .max_id
40
- where " date" >= ' 2022-10 -00' -- the recovery-period start date
41
- and " date" < ' 2023-01 -00' -- one day after the recovery-period end date
43
+ where " date" >= ' 2024-04 -00' -- the first day of the recovery period
44
+ and " date" < ' 2024-07 -00' -- one day after the recovery-period end date, typically three months after the start
42
45
and u .subscription_id in (
43
46
select distinct subscription_id
44
47
from accounting .cost_recovery
@@ -52,6 +55,7 @@ group by
52
55
53
56
-- Export Query 3
54
57
-- Include the finance rows
58
+ -- Outputs sheet max-recoverable_YY-YY_qN
55
59
select sd .display_name ,
56
60
f .id ,
57
61
f .subscription_id ,
70
74
on latest_names .subscription_id = f .subscription_id
71
75
join accounting .subscription_details sd
72
76
on sd .id = latest_names .max_id
73
- where f .date_to >= ' 2022-10 -00' -- the recovery-period start date
74
- and f .date_from < ' 2023-01 -00' ; -- one day after the recovery-period end date
77
+ where f .date_to >= ' 2024-04 -00' -- the first day of the recovery period
78
+ and f .date_from < ' 2024-07 -00' ; -- one day after the recovery-period end date, typically three months after the start
75
79
76
80
77
81
-- Data Integrity Query 1
0 commit comments