single
Funnel Analysis with CASE WHEN + SUM
Deslize para mostrar o menu
Funnel analysis is a core technique in analytics for understanding how users or leads progress through a series of defined business stages, such as from initial awareness to final purchase. In SQL, you can build funnel reports by using the CASE WHEN statement to classify records into funnel stages, and then aggregate these classifications to count the number of users or leads at each stage. This approach allows you to visualize where users drop off and where they convert, providing actionable insights for optimizing business processes.
A funnel stage represents a key step in a user's journey, such as "Lead," "Trial," or "Paid."
A conversion rate is the percentage of users who move from one stage to the next. For example, if 100 users start a trial and 30 become paid customers, the conversion rate from "Trial" to "Paid" is 30%.
123456SELECT COUNT(*) AS total_leads, SUM(CASE WHEN status = 'Contacted' THEN 1 ELSE 0 END) AS contacted_leads, SUM(CASE WHEN status = 'Converted' THEN 1 ELSE 0 END) AS converted_leads FROM leads WHERE campaign_id = 8;
The marketing team often needs to understand the effectiveness of their campaigns. For example, they may request a funnel report showing the number of leads generated, how many of those leads started a trial, and how many ultimately converted to paid customers for the last campaign. This type of report helps them identify which steps in the funnel are performing well and which need improvement.
123456789SELECT COUNT(*) AS total_leads, SUM(CASE WHEN status = 'Contacted' THEN 1 ELSE 0 END) AS trials_started, SUM(CASE WHEN l.status = 'Converted' AND c.conversion_id IS NOT NULL THEN 1 ELSE 0 END) AS paid_conversions FROM leads l LEFT JOIN conversions c ON l.lead_id = c.lead_id WHERE campaign_id = ( SELECT MAX(campaign_id) FROM campaigns );
Now, you will apply these concepts to measure drop-off rates between each stage in the sales funnel. Understanding drop-off at each step is crucial for optimizing the funnel and improving conversion rates.
Deslize para começar a programar
Write a SQL query to calculate the drop-off rate between each stage of the sales funnel for the most recent campaign.
- Count the total number of leads for the most recent campaign.
- Count the number of leads who reached the "Contacted" stage.
- Count the number of leads who reached the "Converted" stage.
- Calculate the drop-off percentage from "Lead" to "Contacted" as the percentage of leads who did not reach "Contacted."
- Calculate the drop-off percentage from "Contacted" to "Converted" as the percentage of contacted leads who did not convert.
Solução
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo