Отток.txt
| 1 |
CREATE OR REPLACE VIEW public.customer_churn |
|---|---|
| 2 |
AS SELECT sf.year_month, |
| 3 |
sf.clientaltkey, |
| 4 |
sf.group_format, |
| 5 |
sf.region, |
| 6 |
sf.format, |
| 7 |
sf.revenue, |
| 8 |
sf1.year_month_future, |
| 9 |
sf1.group_format_future |
| 10 |
FROM segmentation_formats sf |
| 11 |
LEFT JOIN ( SELECT DISTINCT segmentation_formats.year_month AS year_month_future, |
| 12 |
segmentation_formats.clientaltkey, |
| 13 |
segmentation_formats.group_format AS group_format_future |
| 14 |
FROM segmentation_formats) sf1 ON sf.clientaltkey::text = sf1.clientaltkey::text AND sf.year_month = (sf1.year_month_future - '1 mon'::interval) |
| 15 |
WHERE sf.year_month >= '2025-01-01'::date; |