SQL interview question: A/B test conversion rate by platform

MediumA/B tests

Problem

Shared data rules

Compare order conversion between new_cart control and treatment, for each platform and for all participants together. Converted = placed an order within 7 days after assignment.

Formula

Example

Input: users
user_idplatform
1ios
2ios
3android
4android
5android
Input: experiments
user_idexperiment_namevariantassigned_atRow note
1new_cartcontrol2026-09-10 12:00
2new_carttreatment2026-09-10 15:00
3new_cartcontrol2026-09-11 11:00
4new_carttreatment2026-09-12 13:00
5new_cartcontrol2026-09-13 10:00
5new_carttreatment2026-09-16 10:00← repeat assignment — ignored
Input: orders
order_iduser_idcreated_atstatusRow note
10112026-09-09 18:00delivered← before assignment
10212026-09-17 12:30delivered← 7 d 30 min later — late
10322026-09-13 13:00delivered
10432026-09-14 10:00delivered
10552026-09-14 15:00delivered← within the first assignment’s window
Output
segmentcontrol_userstreatment_usersconv_controlconv_treatmentdiff_pp
ios1101100
android2110-100
all320.66670.5-16.67

all: 2 of 3 converted in control and 1 of 2 in treatment: (0.5 − 0.6667) × 100 = −16.67.

Output columns

segment
the participant’s platform (users.platform), or all for everyone
Solve it free

Your query runs on PostgreSQL in your browser. No sign-up needed.

Skills it tests

More interview questions

All questions