Back to Practice
#0375

Visit to Purchase Conversion Rate

HardSQL35 min25 XP

Problem

Return conversion_rate as distinct purchasers divided by distinct visitors.

Why This Matters

SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.

Schema

events(user_id INTEGER, event_name TEXT)

Examples

Example 1
Input3 visitors, 2 purchasers
Output0.6666...

Multiplying by 1.0 forces floating-point division in SQLite.

Constraints

  • Return only the requested columns.
  • Use deterministic ORDER BY when multiple rows are returned.
  • Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Input3 visitors, 2 purchasers
Expected[[0.6666666666666666]]

Multiplying by 1.0 forces floating-point division in SQLite.

Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks