0PricingLogin
SQL Interview Prep · Lesson

A/B Test Assignment and Metrics

Joining experiment assignment to outcomes and computing per-variant metrics.

What an A/B Test Question Tests

A/B test questions check whether you can correctly join experiment assignment to outcomes and compute a clean per-variant metric.

The trap is almost always in the join: counting outcomes for users who were never enrolled, or double-counting users assigned twice. Get the assignment join right and the metrics are easy arithmetic.

The Two Tables You Get

Expect an assignment table and an outcome table:

  • assignments(user_id, variant, assigned_at) where variant is 'control' or 'treatment'.
  • orders(user_id, order_id, amount, created_at) or a generic events table.

Assignment is the source of truth for who is in the experiment. Outcomes only count if the user appears in assignment.

CREATE TABLE assignments (
  user_id     INT,
  variant     VARCHAR(20),
  assigned_at TIMESTAMP
);

CREATE TABLE orders (
  user_id    INT,
  order_id   INT,
  amount     NUMERIC,
  created_at TIMESTAMP
);

All lessons in this course

  1. Building a Multi-Step Funnel
  2. Ordered Events and Time Windows
  3. A/B Test Assignment and Metrics
  4. Lift, Significance and Guardrails in SQL
← Back to SQL Interview Prep