From 062a80fafa0574619a2f58d6f7e6affcb0aa4f68 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Mon, 24 Jul 2023 19:22:47 -0400 Subject: [PATCH] more analytics, etc. queries --- .../analytics/users/paying_user_interests.sql | 44 ++++++++++++++++++- .../voice_conversion_models.sql | 4 +- .../basic_user_queries.sql} | 0 _sql/analytics_stripe_sigma/user_cohorts.sql | 8 ++++ 4 files changed, 54 insertions(+), 2 deletions(-) rename _sql/{analytics/users/stripe_sigma_queries.sql => analytics_stripe_sigma/basic_user_queries.sql} (100%) create mode 100644 _sql/analytics_stripe_sigma/user_cohorts.sql diff --git a/_sql/analytics/users/paying_user_interests.sql b/_sql/analytics/users/paying_user_interests.sql index c208150b32..89b095f079 100644 --- a/_sql/analytics/users/paying_user_interests.sql +++ b/_sql/analytics/users/paying_user_interests.sql @@ -37,7 +37,7 @@ FROM ( x.use_count > 10; --- The first voice a paying customer uses +-- The first TTS voice a paying customer uses -- TODO: List *all* of the voices a paying customer uses before they subscribe, not just the first. -- select first row of partially aggregate query: https://stackoverflow.com/a/73157541 SELECT * @@ -78,6 +78,48 @@ FROM ( ) AS z ORDER BY use_count desc + +-- The first VC voice a paying customer uses +-- TODO: List *all* of the voices a paying customer uses before they subscribe, not just the first. +-- select first row of partially aggregate query: https://stackoverflow.com/a/73157541 +SELECT * +FROM ( + SELECT + m.token, + m.title, + count(*) as use_count, + m.created_at, + m.user_deleted_at, + m.mod_deleted_at + FROM voice_conversion_models AS m + JOIN + ( + SELECT + model_token + FROM ( + SELECT + maybe_model_token as model_token, + maybe_creator_user_token, + row_number() over(partition by maybe_creator_user_token order by id asc) as rownum + FROM + generic_inference_jobs + WHERE maybe_model_token IS NOT NULL + AND maybe_creator_user_token IN + ( + select distinct user_token + from user_subscriptions + where created_at > (CURDATE() - INTERVAL 2 DAY) + ) + ) AS x + WHERE rownum = 1 + ORDER BY model_token desc + ) AS y + ON m.token = y.model_token + GROUP BY m.token + ) AS z +ORDER BY use_count desc + + -- The last voice a paying customer uses -- select first row of partially aggregate query: https://stackoverflow.com/a/73157541 SELECT * diff --git a/_sql/analytics/voice_conversion/voice_conversion_models.sql b/_sql/analytics/voice_conversion/voice_conversion_models.sql index 459814a0b7..0663cec77f 100644 --- a/_sql/analytics/voice_conversion/voice_conversion_models.sql +++ b/_sql/analytics/voice_conversion/voice_conversion_models.sql @@ -35,7 +35,9 @@ left join users AS u on where vc.user_deleted_at IS NULL and vc.mod_deleted_at IS NULL -order by vc.original_download_url ASC; +order by vc.title asc; + +-- order by vc.original_download_url ASC; -- -- Top 100 voice conversion models by use count diff --git a/_sql/analytics/users/stripe_sigma_queries.sql b/_sql/analytics_stripe_sigma/basic_user_queries.sql similarity index 100% rename from _sql/analytics/users/stripe_sigma_queries.sql rename to _sql/analytics_stripe_sigma/basic_user_queries.sql diff --git a/_sql/analytics_stripe_sigma/user_cohorts.sql b/_sql/analytics_stripe_sigma/user_cohorts.sql new file mode 100644 index 0000000000..bd5947157a --- /dev/null +++ b/_sql/analytics_stripe_sigma/user_cohorts.sql @@ -0,0 +1,8 @@ +-- 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. + +