KatInterview

Topic

SQL & Data interview problems

Joins, window functions, aggregation and data cleaning in Python. 239 original problems, each with hidden test cases you can run in the browser.

Problems239

27 easy200 medium12 hard

Showing 91–120 of 239 results

  • Filter viewing events to premium subscribers, bucket them into Monday-start weeks and calendar months per user, sum minutes into hours, and return a sorted long-format result.

    Auto-gradedaggregationgroup-bydateshash-map
  • Design one metric that blends click-through and purchase quality, then write SQL that attributes clicks to impressions and reports it per ad for the past week.

    Model answersqljoinswindow-functionsmetrics
  • Clean a job-postings table, compute invitation-weighted reply rates per category with 95% Wilson intervals, rank the top 5, and check the weighting identity numerically.

    Model answerpandasgroupbywilson-intervaldata-cleaning
  • Join two small tables in pandas, then build channel revenue totals, a member-by-channel pivot, per-state order and buyer counts, and a rule-based high-value flag.

    Model answerpandasmergegroupbypivot_table
  • Clean a customer CSV with ordered null-handling rules and compute two averages in tidyverse R, then write one MySQL 8 query returning the top half of students by average grade.

    Model answersqlrtidyversewindow-functions
  • Compute, for each record, the total of all values in the dataset that do not exceed its own value, handling ties and large inputs efficiently via grouping and a running total.

    Auto-gradedaggregationprefix-sumsortinghash-map
  • Build a point-in-time snapshot of profiles whose latest version has an approved final review, add 7-day engagement and country rollups, and write data-quality and rerun-safety checks.

    Model answersqlwindow-functionspoint-in-time-snapshotdata-validation
  • Define a precise rule for excessive headset use, then write SQL that counts flagged users, active users, and the flagged share over a trailing 30-day window.

    Model answersqlgaps-and-islandswindow-functionsmetric-definition
  • Write SQL that finds the worst advertisers by report-to-visit rate, picks each one's worst ad, and builds a daily leaderboard without double-counting visits or reports.

    Model answersqlwindow-functionsaggregationjoins
  • Write SQL that deduplicates ad event logs, restricts them to a one-week UTC window, and computes click-through rate overall and per campaign type, with safe handling of zero impressions.

    Model answersqlaggregationdeduplicationconditional-aggregation
  • Filter records by a status value, total a numeric field per customer ID, and return the results sorted by ID, mirroring a SQL filter, group and order query in Python.

    Auto-gradedhash-mapaggregationgroup-bysorting
  • Given team and game record lists, find the 2023 championship winner when the winner may be on either side, with a deterministic highest-score tie-break.

    Auto-gradeddata-manipulationjoinsfilteringhash-map
  • Given user and post records with timestamps, count per signup date how many users published at least one post that same calendar day, counting each user once.

    Auto-gradedhash-mapdatesdedupaggregation
  • Work out exact join and blend results on two small tables, then explain how filter order, fan-out and granularity change the numbers and when blending is the better choice.

    Model answertableaudata-blendingjoinsorder-of-operations
  • Diagnose a multi-join SQL report that undercounts mulch sales, trace the lost rows step by step, and rewrite it to return all 30 days with correct totals.

    Model answersqlleft-joinwhere-vs-ondate-spine
  • Join two record lists on a composite key with missing-row defaults, then compute a filtered distinct count, a per-group top-5 ranking with tie-breaks, and an every-item condition check.

    Auto-gradedjoinsgroup-byrankingtie-breaking
  • Diagnose a failing Hive INSERT...SELECT into a partitioned ACID ORC table and explain, in order, the fixes for syntax, alignment, casts, partitions, settings and format.

    Model answerhiveinsert-selectdynamic-partitionstype-casting
  • Aggregate line-item spend by shopper and category, rank with ties, keep the top two ranks, add spend share, and handle shoppers with no purchases.

    Auto-gradedaggregationgroupingrankingjoins
  • Compute which category has the highest mean watch time across valid video rows, with null and nonpositive filtering, name lookup, lexicographic tie-breaks, and rounding.

    Model answerpandasaggregationhash-mapdata-cleaning
  • Write warehouse SQL that turns daily participation logs into a treatment-aware employee-day panel and a site-week participation table for a staggered-rollout DiD analysis.

    Model answersqldifference-in-differencespanel-dataleft-join
  • Analyze how one composite InnoDB index handles three query shapes, covering leftmost-prefix seeks, ordering, range limits, index condition pushdown, and the cost of row lookups.

    Model answermysqlinnodbcomposite-indexcovering-index
  • Join and aggregate social-graph records to compute per-user reach scores and per-month follower statistics, including previous-month lookups, growth rates and running totals.

    Auto-gradedaggregationjoinswindow-functionshash-map
  • Write a query that totals each employee's first-quarter take-home pay and flags those whose most recent paycheck fell below the one before it, with the percentage drop.

    Model answersqlwindow-functionsaggregationcte
  • Three short data-engineering questions: contrast pandas Series and DataFrame, explain when SQL applies WHERE versus HAVING, and write a query that reports emails occurring more than once.

    Model answersqlpandasgroup-byhaving
  • Reduce salary history to each person's current pay per department, then choose the highest-paid person in each department, with exact tie and ordering rules.

    Auto-gradedgroupinghash-mapdata-manipulationtop-n-per-group
  • Write one SQL query that classifies devices as new, retained or churned for 2025-09-01 from a raw event log, and reports net growth overall and per platform.

    Model answersqlcteretentiondeduplication
  • Filter orders by inclusive membership windows, total quantities per day and customer, and return every customer tied for each day's maximum, in sorted order.

    Auto-gradedaggregationgroup-bytiesdate-range-filter
  • Build a per-user cohort from coupon events, then join transactions by time window to compute cohort size, converters, and spend within 48 hours.

    Auto-gradedjoinshash-mapdatetimeaggregation
  • Aggregate two conditional counts per group from two related row lists, keeping groups with no matching rows and handling both boolean and string status values.

    Auto-gradedconditional-aggregationleft-joinhash-mapgroup-by
  • Deduplicate retried events, split each user's activity into sessions on gaps over 30 minutes, and summarize each session with its start, end and distinct page count.

    Auto-gradedsessionizationwindow-functionsdeduplicationgaps-and-islands

More topics