problems

SQL interview style questions. Write the query, run it on the sample data, then submit. Every submission is graded on named edge cases, random data and a large dataset, so it has to actually be right, and fast enough. Pick PostgreSQL, MySQL or SQL Server, the output has to be the same either way.

0/22 solved

app activity

product analytics
about this dataset

A mobile / web app that logs every user action as an event. This is the classic product analytics setup: daily actives, streaks, retention, sessions, funnels. Big tech data and analyst interviews are full of these.

  • event_type is one of app_open, view_item, add_to_cart, purchase
  • a user can have many events per day, and two events can have the exact same timestamp
  • "day" always means the calendar date of event_ts

Answers are checked on the sample data, named test cases, random data and a large dataset, so don't hardcode anything you see in the sample.

  1. Daily active usersaggregation · COUNT DISTINCT · dateseasy
  2. Longest activity streakgaps and islands · window functionshard
  3. Day 7 retention by cohortretention · cohorts · LEFT JOIN · percentagesmedium
  4. Sessions per usersessionization · LAG · running sumhard
  5. Funnel by platformfunnels · ordering of events · conditional countshard
  6. Rolling 7 day average DAUdate spine · window frames · rolling averagehard

SQL developer assessment

banking
about this dataset

Four questions on a small banking database. Each answer has to be a single SQL statement, CTEs (WITH ...) are fine, no procedural code, loops, cursors or temp tables.

The sample data is for reference only. When you submit, your query also runs against hidden test cases, random datasets and a large dataset with tens of thousands of accounts. So don't hardcode ids, names, dates or row counts you see in the sample. The only fixed values you can use are the ones written in the question (like 2026-06-30).

Column types: ids and codes are text, *_date columns are DATE, *_ts columns are TIMESTAMP, amounts are NUMERIC.

  1. Latest balancehard
  2. June transaction counthard
  3. Worst loan per branchhard
  4. Balance dropshard

company HR

hrclassic
about this dataset

A company's employees, their managers and departments. The questions here are the classics every SQL interview seems to have a version of: top earner per department, earns more than their manager, second highest salary, median, headcount over time, org chart depth.

  • manager_id points at another employee. The top of the org has no manager (NULL).
  • termination_date is NULL for people who still work here. Someone is a current employee if termination_date is NULL.
  • a department can have no employees at all

Answers are checked on the sample data, named test cases, random data and a large dataset, so don't hardcode anything you see in the sample.

  1. Highest paid per departmentwindow functions · tieseasy
  2. Earns more than their managerself joineasy
  3. Second highest salary per departmentDENSE_RANK · distinct values · LEFT JOINmedium
  4. Median salary by departmentpercentiles · statisticsmedium
  5. Headcount at every month enddate spine · non-equi join · point in timehard
  6. Org chart depthrecursive CTE · hierarchyhard

online store

e-commerce
about this dataset

An online store with customers, products, orders and the items in each order. These are the kind of questions product and data analyst interviews love: top N per group, growth, conversion, repeat rate, anti-joins.

A few things that hold for every question here:

  • an order's status is completed, cancelled or refunded. Only completed orders count as sales unless the question says otherwise.
  • revenue for an order line is quantity * unit_price. unit_price is what the customer actually paid, it can be lower than the product's list price.
  • customer_id on an order can be NULL (guest checkout).

Answers are checked on the sample data, named test cases, random data and a large dataset, so don't hardcode anything you see in the sample.

  1. Top 3 products per categorywindow functions · top N per group · tiesmedium
  2. Monthly revenue growthdate functions · period over period · gapshard
  3. First purchase within 7 daysconversion · aggregation · date mathmedium
  4. Repeat buyers by countryaggregation · conditional counts · percentagesmedium
  5. Laptops but no accessoriesanti-join · NOT EXISTS · NULL trapsmedium
  6. Average days between ordersLAG · window functions · date mathhard