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
Clean and Reshape Timesheet Data
00:00
5 left

Clean and Reshape Timesheet Data

HardSQL · PostgreSQL

Problem

Tessella's analytics team receives timesheet extracts with inconsistent formatting, duplicate updates, missing references, and mixed approval states. Write a PostgreSQL query that converts the raw extract into a monthly analysis-ready table.

Requirements

  1. Keep only the latest record for each timesheet_id, based on updated_at.
  2. Parse the date and decimal hours, normalize billable flags, and retain approved rows with hours from 0 through 24.
  3. Use left joins to retain approved entries even when the consultant or project reference is missing. Label missing references as Unknown consultant or Unknown project.
  4. Aggregate by month, consultant, and project, returning total, billable, non-billable hours, and entry count. Sort chronologically, then by consultant and project.

Schema

raw_timesheets
ColumnTypeDescription
timesheet_idINTLogical identifier for a timesheet entry
ingestion_idPKINTUnique raw ingestion row identifier
consultant_idINTConsultant reference
project_codeVARCHAR(20)Project reference
work_date_textVARCHAR(20)Work date stored as text in DD/MM/YYYY format
hours_textVARCHAR(20)Hours stored as text
billable_textVARCHAR(10)Text representation of billable status
statusVARCHAR(20)Timesheet approval status
updated_atTIMESTAMPTimestamp of the raw row update
consultants
ColumnTypeDescription
consultant_idPKINTConsultant identifier
consultant_nameVARCHAR(100)Consultant full name
projects
ColumnTypeDescription
project_codePKVARCHAR(20)Project code
project_nameVARCHAR(100)Project name
Tablesraw_timesheetsconsultantsprojects
Interviewer

Your question is Clean and Reshape Timesheet Data. Start with the requirements and the three 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.