Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Optimizing Slow Queries
00:00
5 left

Optimizing Slow Queries

MediumSQL · PostgreSQL

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
Interviewer

Your question is Optimizing Slow Queries. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.