Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Rolling 7-Day Conversion SQL

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Rolling 7-Day Conversion SQL. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

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

Problem

Business context

Shopify Marketing analysts monitor the performance of the Shopify Email channel across consecutive days. The team needs a rolling conversion rate that remains accurate when a day has traffic but no conversions, or no traffic at all.

Task

Write a PostgreSQL query for the period from March 1 through March 10, 2025, using only the Shopify Email channel.

Requirements

  1. Generate one output row for every calendar date, including dates with no sessions.
  2. Calculate daily distinct sessions and daily distinct sessions with at least one completed order.
  3. Calculate seven-day rolling totals using the current date and preceding six calendar days.
  4. Return the rolling conversion rate as a percentage rounded to two decimals, with safe division when there are no sessions.
  5. Prevent multiple orders from inflating session counts, and sort chronologically.

Schema

shopify_marketing_sessions
ColumnTypeDescription
session_idPKINTUnique marketing session identifier
session_dateDATEDate on which the session occurred
channelVARCHAR(100)Shopify Marketing attribution channel
campaign_nameVARCHAR(150)Shopify Email campaign name
shopify_orders
ColumnTypeDescription
order_idPKINTUnique order identifier
session_idINTMarketing session attributed to the order
order_dateDATEDate on which the order was placed
statusVARCHAR(30)Order lifecycle status
Tablesshopify_marketing_sessionsshopify_orders
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results