KatInterview

practice a little every day — you've got this ♡

SQL Interview Problems

Practice 5969 original coding, SQL, system design, machine learning and behavioral problems across 15 topics. Coding and SQL problems run against hidden test cases right in your browser; every problem has hints and a worked solution, free.

5969
Problems
2211
Auto-graded
15
Topics
273
Added today

Showing 91–120 of 139 results

  • SQL & DataMediumModel answer
    Schema Design for a Video Streaming Service

    Design a relational database schema for a large-scale video platform, addressing scalability, GDPR compliance, and analytics requirements.

    SQL & Datadatabase-designschema-modelingindexingpartitioning
  • SQL & DataMediumModel answer
    Rolling Week Averages with Calendar-Based Windows

    Calculate a 7-day moving average for each date using calendar intervals, not row counts, handling gaps and NULL values correctly.

    SQL & Datawindow-functionsdate-arithmeticaggregation
  • SQL & DataMediumModel answer
    Hourly Click-Through Rate and Local Revenue by Country

    Calculate hourly CTR and currency-adjusted revenue per country from event logs, joining latest exchange rates and handling time bucketing and safe division.

    SQL & Dataaggregationjoinswindow-functionsdate-time
  • SQL & DataMediumModel answer
    Daily and Category-Level New Customer Purchase Rate

    Flag each order as a customer's first in a category or overall, then aggregate to compute new-buyer proportions by day and category.

    SQL & Datasqlpandaswindow-functionsaggregation
  • SQL & DataHardModel answer
    Reconstruct the Latest State of Every Listing

    Query an event-log table to produce one row per listing showing its most recent status and total lifespan in hours.

    SQL & Datawindow-functionsaggregationtimestamp-arithmetic
  • SQL & DataHardModel answer
    Multi-Stage Funnel Analysis in SQL: Windows, Dedup & Rollups

    Write ANSI-SQL to build a windowed conversion funnel, attribute acquisition channels, flag bot-like campaigns, deduplicate near-duplicate events, and compute rolling unique viewers.

    SQL & Datafunnel-analysiswindow-functionsCTEsdeduplication
  • SQL & DataMediumModel answer
    Daily Funnel Metrics and 1-Day Retention in SQL and pandas

    Build a validated event layer, then compute daily funnel counts, per-user first-event dates, and a one-day retention rate using SQL and pandas.

    SQL & Datasqlpandasfunnelretention
  • SQL & DataMediumModel answer
    Window Ranking Functions: Choosing the Right One for Top-N Queries

    Explain how ROW_NUMBER, RANK, and DENSE_RANK behave differently when ties exist, and which to use depending on what "top N" actually means.

    SQL & Datawindow-functionsrankingtiestop-k
  • SQL & DataMediumModel answer
    Predicting the Output of a Join + Aggregate + Window Query

    Read a multi-clause SQL query against two small tables and state exactly which rows come back, with each column value, traced stage by stage.

    SQL & Datasqljoinswindow-functionsnulls
  • SQL & DataMediumModel answer
    Campaign Attribution: Define Metrics and Write SQL for Purchase Impact

    Design attributable, time-bounded conversion metrics for a marketing campaign and implement the SQL to measure, baseline, and diagnose them across a five-table schema.

    SQL & Datasqlmetricsattributionwindow-functions
  • SQL & DataMediumModel answer
    SQL Window Functions, Join Cardinalities, Dedup, and Pandas Merges

    Work through ten interconnected SQL and pandas tasks spanning aggregations with NULL handling, join types, set operations, window functions, views, duplicate management, and indexing strategy.

    SQL & Datasqlpandaswindow-functions
  • SQL & DataMediumModel answer
    Cohort Engagement Metrics for Single-Category Users

    Filter users into mutually exclusive content-type cohorts, then compute activity counts, median active days, a 10-day threshold rate, and per-user average minutes.

    SQL & Datacohort-analysisaggregationwindow-functionsdata-quality
  • SQL & DataMediumModel answer
    Payment Risk Scoring with Rolling Windows and NULL Handling in SQL

    Analyze a payments table to rank users by declined volume, flag burst activity in 24-hour windows, and classify each transaction by amount using conditional logic.

    SQL & Datawindow-functionsaggregationcase-whennull-handling
  • SQL & DataMediumModel answer
    SQL Window Functions, Join Types, and Python Aggregation

    Demonstrate SQL window functions, join semantics, ranking functions, string aggregation, and Python dict-based accumulation over transactional row data.

    SQL & Datawindow-functionsjoinsaggregationpython
  • SQL & DataMediumModel answer
    Compare Acquisition Channels by Spend, Retention, and Early Revenue

    Write SQL to profile marketing channels across four dimensions: user counts, top spenders, cohort retention, and 90-day ARPU.

    SQL & Datawindow-functionscohort-analysisaggregationjoins
  • SQL & DataMediumModel answer
    Validate and Aggregate Subscription Event Data

    Profile a subscription events table to verify data integrity, then compute the earliest active date and most recent inactive date per subscription.

    SQL & Datasqlpandasdata-validationtime-series
  • SQL & DataMediumModel answer
    Quarter-over-Quarter Revenue Analysis with Same-Store Metrics

    Build a SQL query that compares quarterly performance across different time periods, handling store openings/closings and computing both total and same-store growth rates.

    SQL & Datasqlaggregationtime-seriesanalytics
  • SQL & DataMediumModel answer
    Per-Category Top-10 Items: Revenue Share Analysis

    Write a SQL query ranking the top 10 items by revenue within each category and compute what fraction of each category's total revenue those items represent.

    SQL & Datawindow-functionsaggregationCTEsranking
  • SQL & DataMediumModel answer
    Time-Zone-Aware Activity Drop Detection Query

    Write SQL to find countries where the most creators posted significantly less in the recent week than their baseline, accounting for local time zones.

    SQL & Datasqlwindow-functionstime-seriesaggregation
  • SQL & DataMediumModel answer
    SQL Analysis and Statistical Testing of App Usage Patterns

    Write SQL queries to identify top apps and compute category distributions, then design a statistical test to compare engagement frequency across user segments.

    SQL & Datasqlaggregationwindow-functionsstatistical-testing
  • SQL & DataEasyModel answer
    Highest Spender in the Company's First Decade

    Identify which user spent the most money during the initial ten-year period starting from the company's very first transaction.

    SQL & Datasqlaggregationwindow-functionsdate-filtering
  • SQL & DataMediumModel answer
    Fix a Promotion Join That Silently Drops Sales Rows

    Diagnose and repair a multi-table SQL query that loses rows due to a NULL-breaking join, UTC date bucketing, and promotion fan-out inflation.

    SQL & Datajoinsdatetimewindow-functionsdebugging
  • SQL & DataMediumModel answer
    Rolling Window Metrics for Digital Ad Campaign Data

    Compute impression rankings, conversion rates by format, per-user revenue, and peak traffic hours from ad event tables using SQL aggregation and joins.

    SQL & Datasqlaggregationjoinswindow-functions
  • SQL & DataMediumModel answer
    Filter users by location and rank forums by activity

    Write SQL to classify users as US-based using profile and IP data, then identify the top forums by post volume and distinct contributors over a rolling 30-day window.

    SQL & Datasqlaggregationjoinswindow-functions
  • SQL & DataMediumModel answer
    SQL Net Revenue Rankings and Transaction Data Quality Checks

    Write SQL queries to rank vendors by net revenue globally and by city/state, then design and implement data quality checks on a transaction table.

    SQL & Datasqlwindow-functionsdata-qualityaggregation
  • SQL & DataMediumModel answer
    Freight Analytics: Top States, Daily Rates, and Running Totals

    Join three logistics tables to rank states by completed jobs, compute daily average rates, and build a running cumulative count using window functions.

    SQL & Datawindow-functionsaggregationjoinscte
  • SQL & DataMediumModel answer
    Compute Daily Conversion and User Order History with Deduplication

    Write SQL to calculate daily conversion metrics and per-user order summaries over a week, handling event deduplication and missing days.

    SQL & Datawindow-functionsaggregationdeduplicationdate-ranges
  • SQL & DataMediumModel answer
    Build Candlestick Bars from a Raw Price Feed

    Parse a string of price-timestamp ticks, bucket them into fixed-width time windows, compute OHLC stats, and forward-fill any empty windows.

    SQL & Datatime-seriesaggregationdata-manipulationpython
  • SQL & DataMediumModel answer
    Retrieve and rank teams from a paginated REST API

    Build a client that fetches all pages of team records, handles retries and rate limits, then returns the top n teams sorted by wins descending and name ascending.

    SQL & Datapaginationapierror-handlingsorting
  • SQL & DataMediumModel answer
    Resilient Paginated API Client with Aggregation

    Build a robust script that authenticates against a paginated REST API, handles rate limits and bad records, and produces serialized output plus top-k category aggregates.

    SQL & Datapythonrest-apipaginationdata-pipeline