Recency가 90일 이상인 유저 수 / 총 유저 수 x 100
WITH Churned AS (
SELECT *
FROM customer2
WHERE recency >= 90
)
SELECT
COUNT(Churned.id) AS ChurnedCount,
COUNT(customer2.id) AS TotalCustomers,
COUNT(Churned.id) / COUNT(customer2.id) * 100 AS ChurnedRate
FROM customer2
LEFT JOIN Churned ON customer2.id = Churned.id;
20대,30대,40대,50대,60,70대 이상
40,50,60,30,70,20대순으로 많았음
WITH AgeGroups AS (
SELECT
ID,
CASE
WHEN Year_Birth BETWEEN 1992 AND 1996 THEN '20대'
WHEN Year_Birth BETWEEN 1982 AND 1991 THEN '30대'
WHEN Year_Birth BETWEEN 1972 AND 1981 THEN '40대'
WHEN Year_Birth BETWEEN 1962 AND 1971 THEN '50대'
WHEN Year_Birth BETWEEN 1952 AND 1961 THEN '60대'
WHEN Year_Birth <= 1951 THEN '70대 이상'
END AS AgeGroup,
Recency,
NumDealsPurchases,
NumWebVisitsMonth
FROM
customer2
),
Churned AS (
SELECT *
FROM customer2
WHERE recency >= 90
),
NotChurned AS (
SELECT *
FROM customer2
WHERE recency < 90
)
SELECT AgeGroups.AgeGroup, COUNT(Churned.ID)
FROM AgeGroups
LEFT JOIN Churned ON AgeGroups.ID = Churned.ID
GROUP BY AgeGroup