This repository contains SQL queries used to analyze customer churn in a telecom dataset. The dataset is stored in a database table named telcom_clean_data#csv$. The queries provide insights into churn rate, revenue contribution, and factors influencing customer churn.
SELECT ROUND(COUNT(CASE WHEN Churn = 1 THEN 1 END) * 100.0 / COUNT(*), 2) AS Churn_Rate
FROM [dbo].[telcom_clean_data#csv$] ;
- This query calculates the percentage of customers who have churned.
SELECT City, COUNT(*) AS Churned_Customers,
(COUNT(*) * 100.0 / (SELECT COUNT(*)
FROM [dbo].[telcom_clean_data#csv$] WHERE Churn = 1)) AS Churn_Percentage
FROM [dbo].[telcom_clean_data#csv$]
WHERE Churn = 1 GROUP BY City HAVING COUNT (*) > 0ORDER BY Churn_Percentage DESC;
- This query identifies the cities with the highest churn rate.
SELECT
CASE
WHEN Age < 30 THEN 'Under 30'
WHEN Age BETWEEN 30 AND 50 THEN '30-50'
ELSE 'Above 50'
END AS Age_Group,
SUM( [Total Revenue]) as Total_revenue_perc
FROM [dbo].[telcom_clean_data#csv$]
GROUP BY CASE
WHEN Age < 30 THEN 'Under 30'
WHEN Age BETWEEN 30 AND 50 THEN '30-50'
ELSE 'Above 50'
END
ORDER BY Total_revenue_perc DESC;
- This query calculates the revenue contribution by different age groups.
SELECT [Online Security], COUNT(*) AS Total_Customers,
SUM(CASE WHEN Churn = 1 THEN 1 ELSE 0 END) AS Churned_Customers,
(SUM(CASE WHEN Churn = 1 THEN 1 ELSE 0 END) * 100.0 / COUNT(*)) AS Churn_Rate
FROM [dbo].[telcom_clean_data#csv$]
GROUP BY [Online Security]
HAVING [Online Security] IS NOT NULL
ORDER BY Churn_Rate DESC;
- This query examines the impact of online security on churn.
SELECT [Contract], COUNT(*) AS Total_Customers,
AVG([Monthly Charge]) AS Avg_Monthly_Charge
FROM [dbo].[telcom_clean_data#csv$]
WHERE [Monthly Charge] IS NOT NULL
GROUP BY [Contract]
ORDER BY Avg_Monthly_Charge DESC;
- This query analyzes how average monthly charges vary by contract type.
SELECT City, COUNT(CASE WHEN Churn = 1 THEN 1 END) AS ChurnedCustomers,
COUNT(*) AS TotalCustomers,
(COUNT(CASE WHEN Churn = 1 THEN 1 END) * 100.0 / COUNT(*)) AS ChurnRate
FROM [dbo].[telcom_clean_data#csv$]
GROUP BY City
ORDER BY ChurnRate DESC;
- This query finds cities with the highest churn rate.
SELECT [Paperless Billing],
COUNT(CASE WHEN Churn = 1 THEN 1 END) AS ChurnedCustomers,
COUNT(*) AS TotalCustomers,
(COUNT(CASE WHEN Churn = 1 THEN 1 END) * 100.0 / COUNT(*)) AS ChurnRate
FROM [dbo].[telcom_clean_data#csv$]
GROUP BY [Paperless Billing]
ORDER BY ChurnRate DESC;
- This query assesses the impact of paperless billing on customer churn.
SELECT
CASE
WHEN CLTV > 5000 THEN 'High Value'
WHEN CLTV BETWEEN 2000 AND 5000 THEN 'Medium Value'
ELSE 'Low Value'
END AS CLTV_Segment,
COUNT(*) AS CustomerCount
FROM [dbo].[telcom_clean_data#csv$]
GROUP BY
CASE
WHEN CLTV > 5000 THEN 'High Value'
WHEN CLTV BETWEEN 2000 AND 5000 THEN 'Medium Value'
ELSE 'Low Value'
END
ORDER BY CustomerCount DESC;
- This query categorizes customers based on their Customer Lifetime Value (CLTV)