-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathdim_orgs.sql
More file actions
46 lines (41 loc) · 904 Bytes
/
dim_orgs.sql
File metadata and controls
46 lines (41 loc) · 904 Bytes
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
WITH orgs AS (
--prod
SELECT
org_id
, org_name
, employee_range
, created_at
FROM {{ ref('org_created') }}
-- --dev
-- SELECT
-- org_id
-- , org_name
-- , employee_range
-- , created_at
-- FROM {{ ref('org_created') }}
)
, user_count AS (
SELECT
org_id
, count(distinct user_id) AS num_users
FROM {{ ref('user_created') }}
GROUP BY 1
)
, subscriptions AS (
SELECT
org_id
, event_timestamp AS sub_created_at
, plan as sub_plan
, coalesce(price, 0) as sub_price
FROM {{ ref('subscription_created') }}
)
SELECT
org_id
, created_at
, num_users
, sub_created_at
, case when num_users = 1 then 'Individual' else sub_plan end as sub_plan
, sub_price
FROM orgs
LEFT JOIN user_count USING (org_id)
LEFT JOIN subscriptions USING (org_id)