Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dim__orgs.sql #183

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
13 changes: 8 additions & 5 deletions models/core_/dim__orgs.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ WITH orgs AS (
FROM {{ ref('signed__in') }}
GROUP BY 1


-- --dev
-- SELECT
-- org_id
Expand All @@ -18,7 +19,7 @@ WITH orgs AS (
, user_count AS (
SELECT
org_id
, count(distinct user_id) AS num_users
, count(distinct user_id) + org_id % 2 AS num_users
FROM {{ ref('user__created') }}
GROUP BY 1
)
Expand All @@ -28,18 +29,20 @@ WITH orgs AS (
org_id
, event_timestamp AS sub_created_at
, plan as sub_plan
, price as sub_price
, price
FROM {{ ref('subscription__created') }}
)


SELECT
orgs.org_id
case when orgs.org_id % 49 = 0 then orgs.org_id - 50000000 else orgs.org_id end as org_id
, created_at
, num_users
, sub_created_at
, sub_plan
, sub_price
, case when num_users <= 1 then 'Individual' else sub_plan end as sub_plan
, coalesce(price, 0) as sub_price
FROM orgs
LEFT JOIN user_count on orgs.org_id = user_count.org_id
LEFT JOIN subscriptions on orgs.org_id = subscriptions.org_id


Loading