fix mistakes with cohort analysis

This commit is contained in:
Dmitry Medvedev
2026-06-29 01:29:36 +05:00
parent 080ce3a251
commit 782f305acd
@@ -1,4 +1,5 @@
CREATE MATERIALIZED VIEW user_cohort_analysis AS
CREATE MATERIALIZED
VIEW user_cohort_analysis AS
SELECT
TO_CHAR(pu.cohort_month, 'YYYY-MM') AS MONTH,
@@ -6,7 +7,8 @@ CREATE MATERIALIZED VIEW user_cohort_analysis AS
COUNT(DISTINCT pe.user_id) AS enrolled_users,
COUNT(DISTINCT plv.user_id) AS active_users,
ROUND(COUNT(DISTINCT plv.user_id) * 100.0 / COUNT(DISTINCT pu.id), 2) || '%' AS retention_rate,
ROUND(AVG((SELECT COUNT(*) FROM pet_courses pc)) / COUNT(DISTINCT pu.id), 2) AS avg_courses_per_user,
ROUND(AVG((SELECT COUNT(pe.id)
FROM pet_enrollments pe)) / COUNT(DISTINCT pu.id), 2) AS avg_courses_per_user,
(SELECT
ROUND(AVG(table_first_viewed_at.first_viewed_at::date - pu2.registration_date::date), 2)
FROM pet_users pu2