-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sung Won Chung
committed
Feb 6, 2024
1 parent
402e32a
commit 1a2ea4a
Showing
3 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
WITH org_events AS ( | ||
SELECT | ||
* | ||
FROM {{ ref('dim_orgs') }} | ||
LEFT JOIN {{ ref('feature_used') }} USING (org_id) | ||
WHERE sub_plan IS NULL or sub_plan = 'Individual' | ||
) | ||
|
||
, final AS ( | ||
SELECT | ||
DISTINCT ORG_ID | ||
, count(*) AS usage | ||
FROM org_events | ||
WHERE | ||
-- select orgs created within the last 60 days, with usage within the 30 days | ||
event_timestamp::date > ('2022-11-01'::date - 30) | ||
AND created_at::date > ('2022-11-01'::date - 60) | ||
GROUP BY 1 | ||
) | ||
|
||
SELECT * FROM final |