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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Aggregate January Approved Annotation Activity
00:00
5 left

Aggregate January Approved Annotation Activity

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

Output details

  • Order both user_id and project_id in ascending order.
  • Break ties between history events at the same event_at using highest history_id first.
  • Treat January bounds as inclusive 2025-01-01 00:00:00 and exclusive 2025-02-01 00:00:00.
  • Treat NULL duration_seconds as 0 when calculating total_duration_seconds.

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 Aggregate January Approved Annotation Activity. 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.