-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathfct__monthly__financials.sql
More file actions
71 lines (59 loc) · 1.96 KB
/
Copy pathfct__monthly__financials.sql
File metadata and controls
71 lines (59 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- WITH final AS (
-- SELECT
-- date_trunc('month', sub_created_at) as date_month
-- , count(distinct org_id) as cnt_subscribers
-- , sum(sub_price) as sum_revenue
-- FROM {{ ref('dim__orgs') }}
-- WHERE sub_created_at is not NULL
-- GROUP BY 1
-- ORDER BY 1
-- )
-- SELECT * FROM final
WITH final AS (
-- SELECT
-- date_trunc('month', sub_created_at) as date_month
-- , count(distinct org_id) as cnt_subscribers
-- , sum(sub_price) as sum_revenue
-- FROM {{ ref('dim__orgs') }}
-- WHERE sub_created_at is not NULL
-- GROUP BY 1
-- ORDER BY 1
{% if target.name == 'sf' %}
SELECT
date_trunc('month', sub_created_at) as date_month
, count(distinct org_id) + 1 as cnt_subscribers
, sum(sub_price) as sum_revenue
FROM {{ ref('dim__orgs') }}
WHERE sub_created_at is not NULL
GROUP BY 1
ORDER BY 1
{% elif target.name == 'db' %}
SELECT
date_trunc('month', sub_created_at) as date_month
, count(distinct org_id) + 1 as cnt_subscribers
, sum(sub_price) as sum_revenue
FROM {{ ref('dim__orgs') }}
WHERE sub_created_at is not NULL
GROUP BY 1
ORDER BY 1
{% elif target.name == 'bq' %}
SELECT
TIMESTAMP_TRUNC(sub_created_at, month) AS date_month,
COUNT(DISTINCT org_id) + 1 AS cnt_subscribers,
SUM(sub_price) AS sum_revenue
FROM {{ ref('dim__orgs') }}
WHERE NOT sub_created_at IS NULL
GROUP BY 1
ORDER BY 1 NULLS LAST
{% else %}
SELECT
date_trunc('month', sub_created_at) as date_month
, count(distinct org_id) + 1 as cnt_subscribers
, sum(sub_price) as sum_revenue
FROM {{ ref('dim__orgs') }}
WHERE sub_created_at is not NULL
GROUP BY 1
ORDER BY 1
{% endif %}
)
SELECT * FROM final