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
Optimize Complex SQL Joins
00:00
5 left

Optimize Complex SQL Joins

HardSQL · PostgreSQL

Problem

Optimize a slow-running SQL query that joins several large tables representing Scale AI user annotation histories. Write a PostgreSQL query that returns approved annotation activity from January 2025, considering only each task's latest history event through January 31. Filter to active projects and aggregate results by user and project.

Output

  1. One row per user and active project with approved tasks in January 2025
  2. Columns: user_id, username, project_id, project_name, approved_tasks, total_duration_seconds, last_approved_at
  3. Order by user_id, then project_id

Schema

scale_users
ColumnTypeDescription
user_idPKINTScale AI user identifier
usernameVARCHAR(100)User display name
teamVARCHAR(100)User's annotation team
projects
ColumnTypeDescription
project_idPKINTScale AI project identifier
project_nameVARCHAR(150)Project name
is_activeBOOLEANWhether the project is currently active
annotation_tasks
ColumnTypeDescription
task_idPKINTAnnotation task identifier
project_idINTReferenced project
assigned_user_idINTUser assigned to the task
task_typeVARCHAR(80)Annotation task type
annotation_history
ColumnTypeDescription
history_idPKINTAnnotation history event identifier
task_idINTReferenced annotation task
statusVARCHAR(30)Task status at this event
event_atTIMESTAMPTime of the status event
duration_secondsINTAnnotation duration in seconds
Tablesscale_usersprojectsannotation_tasksannotation_history
Interviewer

Your question is Optimize Complex SQL Joins. Start with the requirements and the four 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.