DataLane

SQL problem track

Data Quality & Hard SQL

Reconciliation, JSON payloads, pivots, median without percentiles, and sessionization. The back half of the loop.

11 problems · ~180 min total · Data Engineer · ML Engineer · MLOps Engineer · AI Engineer · Data Architect

Track progress 0/11

0% complete

Start with problem 1
  1. Step 1 · ~14 min · Stripe, Capital One, Wise

    Reconcile orders against payments

    A revenue report and a settlement report disagree. Find the orders where the paid amount does not match the order amount — this is the reconciliation check that belongs in a data quality test, not a dashboard.

    Data qualityJoins
    hardProNot started
  2. Step 2 · ~12 min · Snowflake, Databricks, Airbnb

    Traffic source from JSON payload

    events.payload is raw JSON with source and campaign keys. Break activity down by source without unloading the column into a staging table first — this is the semi-structured question every warehouse screen has now.

    Semi-structuredAggregation
    mediumProNot started
  3. Step 3 · ~12 min · Stripe, PayPal, Adyen

    Payment method mix by day

    Turn payment methods from rows into columns so each day is a single row with card, ach, and wallet totals. Warehouses have a PIVOT clause; plain SQL does it with conditional aggregation.

    PivotAggregation
    mediumProNot started
  4. Step 4 · ~18 min · Capital One, JPMorgan, Robinhood

    Median completed order amount

    Report the median completed order amount without a percentile function. The median is the middle value for an odd count and the average of the two middle values for an even count, so the solution has to handle both.

    StatisticsWindow functions
    hardProNot started
  5. Step 5 · ~20 min · Netflix, Spotify, Airbnb

    Sessionize events (30-minute gap)

    Group each customer’s events into sessions that break after 30 minutes of inactivity. This is the three-step gap-and-island pattern: look back, flag a break, then accumulate the flag into an id.

    SessionizationWindow functions
    hardProNot started
  6. Step 6 · ~16 min · Stripe, Adyen, Checkout.com

    Customers who cancelled and completed

    Risk wants customers who both cancelled at least one order and completed at least one order. Return customer_id, cancelled_orders, and completed_orders, smallest customer_id first.

    AggregationData quality
    hardProNot started
  7. Step 7 · ~18 min · Amazon, Instacart, Walmart

    Customers who bought every category

    Marketing wants customers who have purchased at least one product in every product category. Count distinct categories from completed orders only. Return customer_id ascending.

    JoinsAggregationSubqueries
    hardProNot started
  8. Step 8 · ~18 min · Shopify, DoorDash, Uber

    Second order within seven days

    Retention wants customers whose second completed order landed within 7 days of their first completed order. Return customer_id and the days between those two orders, smallest customer_id first.

    Window functionsTime series
    hardProNot started
  9. Step 9 · ~18 min · Stripe, Adyen, PayPal

    Hours from order to settlement

    Treasury wants average hours between ordered_at and paid_at, by payment method. One payment row per paid order in this warehouse. Return method and avg_hours rounded to 2 decimals, slowest method first.

    JoinsTime seriesAggregation
    hardProNot started
  10. Step 10 · ~18 min · Airbnb, Shopify, Meta

    First-touch traffic source

    Growth wants each customer’s first event source. First means earliest occurred_at; tie-break on event_id. Source lives in the JSON payload. Return customer_id and source, smallest customer_id first.

    Window functionsSemi-structuredDeduplication
    hardProNot started
  11. Step 11 · ~16 min · Amazon, DoorDash, Uber

    Customers above average order volume

    CRM wants customers whose completed order count is strictly above the average completed-order count across customers who have at least one completed order. Return customer_id and completed_orders, highest volume first.

    AggregationSubqueries
    hardProNot started

Other tracks

↑↓ navigate openesc close