From 633dfb56829679ffda3a70ce565dbb3de64008b9 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Sun, 29 Jan 2023 20:58:03 -0500 Subject: [PATCH] more queries --- analytics/users/paying_users.sql | 68 +++++++++++++++++++++--- analytics/users/stripe_sigma_queries.sql | 30 +++++++++++ 2 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 analytics/users/stripe_sigma_queries.sql diff --git a/analytics/users/paying_users.sql b/analytics/users/paying_users.sql index 90053b102c..c4a4e11535 100644 --- a/analytics/users/paying_users.sql +++ b/analytics/users/paying_users.sql @@ -13,6 +13,8 @@ select count(*) from user_subscriptions; -- NB: "active" status users are current, treating "past_due" as active too (for now) select count(*) from user_subscriptions where maybe_stripe_subscription_status NOT IN ("canceled", "incomplete", "incomplete_expired"); +-- ==================== TEXT TO SPEECH==================== + -- All paid subscribers generating results in the last week select u.username, count(*) as use_count from users as u @@ -45,7 +47,7 @@ FROM ( ) as t WHERE use_count > 10 --- Paid users gennerating results in the last month +-- Paid users generating results in the last month select u.username, count(*) as use_count from users as u join tts_inference_jobs as j @@ -59,10 +61,64 @@ AND j.created_at > NOW() - interval 1 day GROUP BY u.username ORDER BY use_count desc +-- ==================== WAV2LIP ==================== +select u.username, count(*) as use_count +from users as u + join w2l_inference_jobs as j + on u.token = j.maybe_creator_user_token +WHERE u.token IN ( + select distinct user_token + from user_subscriptions + where maybe_stripe_subscription_status NOT IN ("canceled", "incomplete", "incomplete_expired") +) + AND j.created_at > NOW() - interval 31 day +GROUP BY u.username +ORDER BY use_count desc --- Number of paid users who created a result in the last 7 days -select u.created_at from users as u -where u.token IN - (select distinct u.token from tts_inference_jobs as j join users u on u.token = j.maybe_creator_user_token where j.created_at > now() - interval 7 day) -order by u.created_at ASC; +select username, use_count +FROM ( + select u.username, count(*) as use_count + from users as u + join w2l_inference_jobs as j + on u.token = j.maybe_creator_user_token + WHERE u.token IN ( + select distinct user_token + from user_subscriptions + where maybe_stripe_subscription_status NOT IN ("canceled", "incomplete", "incomplete_expired") + ) + AND j.created_at > NOW() - interval 31 day + GROUP BY u.username + ORDER BY use_count desc + ) as t +WHERE use_count >=5; + +-- ==================== TTS MODELS ==================== + +select u.username, count(*) as use_count +from users as u + join tts_model_upload_jobs as j + on u.token = j.creator_user_token +WHERE u.token IN ( + select distinct user_token + from user_subscriptions + where maybe_stripe_subscription_status NOT IN ("canceled", "incomplete", "incomplete_expired") +) + AND j.created_at > NOW() - interval 1 day +GROUP BY u.username +ORDER BY use_count desc + +-- ==================== W2L TEMPLATES ==================== + +select u.username, count(*) as use_count +from users as u + join w2l_template_upload_jobs as j + on u.token = j.creator_user_token +WHERE u.token IN ( + select distinct user_token + from user_subscriptions + where maybe_stripe_subscription_status NOT IN ("canceled", "incomplete", "incomplete_expired") +) + AND j.created_at > NOW() - interval 1 day +GROUP BY u.username +ORDER BY use_count desc diff --git a/analytics/users/stripe_sigma_queries.sql b/analytics/users/stripe_sigma_queries.sql new file mode 100644 index 0000000000..70b02409a9 --- /dev/null +++ b/analytics/users/stripe_sigma_queries.sql @@ -0,0 +1,30 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- noinspection SqlResolveForFile + +-- NB: These are for use in Stripe Sigma, not MySQL +-- NB: You must use single quotes instead of double quotes when comparing string values. + +-- Histogram of customers by country +select address_country, count(*) +from customers +group by address_country + +select customer_id, subscriptions.status +from subscriptions + + +select distinct customer_id +from subscriptions +where subscriptions.status = 'active' +or subscriptions.status = 'past_due' + +select address_country, count(*) as country_count +from customers +where id IN ( + select distinct customer_id + from subscriptions + where subscriptions.status = 'active' + or subscriptions.status = 'past_due' +) +group by address_country