Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Optimizing Slow Queries

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Optimizing Slow Queries. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Describe a time you had to optimize a slow-running query or a resource-heavy data process.

For this exercise, use the supplied query_runs and analysts tables to produce a concise workload report for January 2025. Include only query fingerprints whose average duration is at least 5,000 milliseconds and that have at least two failed runs.

Output

  1. One row per qualifying query fingerprint, including the analyst name when available.
  2. Columns: query_fingerprint, analyst_name, run_count, avg_duration_ms, and failure_count.
  3. Sort by average duration descending, then query fingerprint ascending.

Schema

query_runs
ColumnTypeDescription
run_idPKINTUnique query execution identifier
query_fingerprintVARCHAR(80)Normalized identifier for a query pattern
owner_idINTAnalyst responsible for the workload
started_atTIMESTAMPTimestamp when execution started
duration_msINTExecution duration in milliseconds
statusVARCHAR(20)Execution outcome
analysts
ColumnTypeDescription
analyst_idPKINTUnique analyst identifier
analyst_nameVARCHAR(100)Analyst display name
team_nameVARCHAR(80)Analyst team
Tablesquery_runsanalysts
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results