194. Kogorta bo'yicha ushlab qolish
QiyinTo'liq analitik so'rov — kogorta tahlili.
Kogorta — bir oyda ro'yxatdan o'tgan foydalanuvchilar guruhi. Har bir
kogorta uchun ro'yxatdan o'tgandan keyin 0, 1, 2, ... oy o'tib
nechtasi hali ham faol bo'lganini o'lchang.
Qadamlar:
- har bir foydalanuvchining ro'yxatdan o'tgan oyi — bu uning kogortasi
- har bir faollik yozuvi uchun kogortadan necha oy o'tganini hisoblang
(month_offset)
- (kogorta, offset) kesimida noyob foydalanuvchilar sonini sanang
retention_pct— shu sonning kogorta boshlang'ich hajmiga nisbati,
foizda, 2 xonagacha
month_offset = 0 uchun retention_pct har doim 100.00.
Oylar farqini shunday hisoblash qulay:
(EXTRACT(YEAR FROM a) - EXTRACT(YEAR FROM b)) * 12 + (EXTRACT(MONTH FROM a) - EXTRACT(MONTH FROM b))
cohort ustuni oyning birinchi kuni (DATE) ko'rinishida chiqsin.
Ustunlar: cohort, month_offset, users, retention_pct.
Saralash: cohort o'sish, keyin month_offset o'sish.
users: id INT PK, signed_up_on DATE
activity: id INT PK, user_id INT, active_on DATE
Namuna ma'lumotlar
| idINT | signed_up_onDATE |
|---|---|
| 1 | 2025-01-10 |
| 2 | 2025-01-22 |
| idINT | user_idINT | active_onDATE |
|---|---|---|
| 1 | 1 | 2025-01-15 |
| 2 | 2 | 2025-01-25 |
| 5 | 1 | 2025-02-11 |
| users | cohort | month_offset | retention_pct |
|---|---|---|---|
| 2 | 2025-01-01 | 0 | 100 |
| 1 | 2025-01-01 | 1 | 50 |
| idINT | signed_up_onDATE |
|---|---|
| 1 | 2025-01-10 |
| 2 | 2025-01-22 |
| 3 | 2025-01-28 |
| 4 | 2025-01-05 |
| 5 | 2025-02-03 |
| 6 | 2025-02-17 |
| 7 | 2025-02-25 |
| 8 | 2025-03-08 |
| 9 | 2025-03-19 |
| idINT | user_idINT | active_onDATE |
|---|---|---|
| 1 | 1 | 2025-01-15 |
| 2 | 2 | 2025-01-25 |
| 3 | 3 | 2025-01-29 |
| 4 | 4 | 2025-01-07 |
| 5 | 1 | 2025-02-11 |
| 6 | 2 | 2025-02-20 |
| 7 | 4 | 2025-02-14 |
| 8 | 1 | 2025-03-05 |
| 9 | 4 | 2025-03-18 |
| 10 | 1 | 2025-04-02 |
| 11 | 5 | 2025-02-05 |
| 12 | 6 | 2025-02-19 |
| 13 | 7 | 2025-02-27 |
| 14 | 5 | 2025-03-12 |
| 15 | 6 | 2025-03-22 |
| 16 | 5 | 2025-04-09 |
| 17 | 8 | 2025-03-10 |
| 18 | 9 | 2025-03-20 |
| 19 | 8 | 2025-04-14 |
| 20 | 2 | 2025-01-30 |
| 21 | 5 | 2025-02-21 |
| users | cohort | month_offset | retention_pct |
|---|---|---|---|
| 4 | 2025-01-01 | 0 | 100 |
| 3 | 2025-01-01 | 1 | 75 |
| 2 | 2025-01-01 | 2 | 50 |
| 1 | 2025-01-01 | 3 | 25 |
| 3 | 2025-02-01 | 0 | 100 |
| 2 | 2025-02-01 | 1 | 66.67 |
| 1 | 2025-02-01 | 2 | 33.33 |
| 2 | 2025-03-01 | 0 | 100 |
| 1 | 2025-03-01 | 1 | 50 |
| idINT | signed_up_onDATE |
|---|---|
| 1 | 2025-02-17 |
| 2 | 2025-01-22 |
| 3 | 2025-03-20 |
| 4 | 2025-01-09 |
| 5 | 2025-01-10 |
| 6 | 2025-02-03 |
| idINT | user_idINT | active_onDATE |
|---|---|---|
| 1 | 6 | 2025-01-25 |
| 2 | 6 | 2025-03-11 |
| 3 | 2 | 2025-02-11 |
| 4 | 3 | 2025-02-25 |
| 5 | 2 | 2025-01-19 |
| 6 | 6 | 2025-02-19 |
| users | cohort | month_offset | retention_pct |
|---|---|---|---|
| 1 | 2025-01-01 | 0 | 33.33 |
| 1 | 2025-01-01 | 1 | 33.33 |
| 1 | 2025-02-01 | -1 | 50 |
| 1 | 2025-02-01 | 0 | 50 |
| 1 | 2025-02-01 | 1 | 50 |
| 1 | 2025-03-01 | -1 | 100 |
O'xshash masalalar
Natijani ko'rish uchun so'rovni ishga tushiring.
