Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Daily Session Funnel Conversion Rates

MediumSQL · PostgreSQL00:00
I
Practice interviewer
Your interviewer
In session
I
Interviewer

Welcome to the SQL screen.

The question is on your right: Daily Session Funnel Conversion Rates. Read through the requirements and the one table first.

Run and submit your code as often as you need. You also have five interviewer messages this session - want to talk through your approach, or are you ready to start coding?

You need to log in / sign up to run or submit.

Problem

Context

A retail analytics team wants to analyze user conversion through the product funnel on a daily basis. Each event in the clickstream_events table is associated with a session. Funnel steps are: product_view, add_to_cart, checkout_start, purchase.

Task

Write a SQL query to compute, for each session start date:

  1. The number of sessions started
  2. The number of sessions with at least one product_view
  3. The number of sessions with at least one add_to_cart
  4. The number of sessions with at least one checkout_start
  5. The number of sessions with at least one purchase
  6. The conversion rate from product_view to add_to_cart (as a decimal, rounded to 1 decimal place)
  7. The conversion rate from product_view to purchase (as a decimal, rounded to 1 decimal place)

Requirements

  • Each session is counted only once per funnel step, regardless of how many times the event occurs in the session.
  • Conversion rates are calculated as: sessions_with_add_to_cart / sessions_with_product_view and sessions_with_purchase / sessions_with_product_view. If the denominator is zero, return 0.0.
  • Output one row per session start date, ordered by date ascending.

Table: clickstream_events

columntypedescription
event_idBIGINTPrimary key
user_idBIGINTUser identifier (not unique per session)
session_idVARCHAR(64)Session identifier; used to group events
event_tsTIMESTAMPEvent timestamp in UTC
event_nameVARCHAR(50)Event type (e.g., product_view, add_to_cart)
page_urlVARCHAR(500)URL where the event occurred; nullable

Schema

clickstream_events
ColumnTypeDescription
event_idPKBIGINTPrimary key
user_idBIGINTUser identifier (not unique per session)
session_idVARCHAR(64)Session identifier; used to group events into sessions
event_tsTIMESTAMPEvent timestamp in UTC
event_nameVARCHAR(50)Event type (e.g., product_view, add_to_cart)
page_urlVARCHAR(500)URL where the event occurred; nullable depending on instrumentation
Tablesclickstream_events
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results