Streaming Cohorts on the Calendar

Streaming Cohorts on the Calendar

You are analyzing the launch of Vela Stream, a subscription video service. Marketing wants to compare viewers activated on different days, weeks, and months, so every subscriber needs three calendar cohort labels. The subscriptions table stores the subscription activation timestamp. A weekly cohort starts on Monday, and a monthly cohort starts on the first calendar day of the month. Ignore rows where activated_at IS NULL. For every subscriber with a known activation time, determine: - the activation day; - the Monday of the activation week; - the first day of the activation month. Return: - subscriber_id; - cohort_day; - cohort_week; - cohort_month. All three cohort columns must be dates displayed as YYYY-MM-DD. Sort by subscriber_id ascending. Return exactly one row per subscriber.

Exemplo de resposta esperada

É assim que se parece uma resposta correta: ela tem seu próprio número de linhas e não precisa coincidir com as tabelas do esquema. Sua resposta precisa retornar os mesmos nomes de colunas do exemplo: use AS para renomeá-las se for preciso.

subscriber_idcohort_daycohort_weekcohort_month
3012025-12-312025-12-292025-12-01
3022026-01-012025-12-292026-01-01
3032026-01-042025-12-292026-01-01
PostgreSQLv16
Entre para enviar

O resultado da sua consulta aparecerá aqui

Focus radio
Paused · SomaFM · Fluid