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
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
Transforming Data with SQL
00:00
5 left

Transforming Data with SQL

HardSQL · PostgreSQL

Problem

Process this data and make these transformations.

Use entities, raw_records, and record_updates. Exclude void records, retain the latest record for each entity and month, apply the latest available correction, normalize negative or missing values to zero, and calculate month-over-month and cumulative values.

Output

  1. One row per entity and retained month.
  2. Columns: entity_name, region, record_month, normalized_value, previous_value, change_amount, cumulative_value.
  3. Order by entity_name, then record_month.

Schema

entities
ColumnTypeDescription
entity_idPKINTUnique entity identifier
entity_nameVARCHAR(100)Entity display name
regionVARCHAR(50)Entity region
raw_records
ColumnTypeDescription
record_idPKINTUnique raw record identifier
entity_idINTReferenced entity
recorded_atDATEDate the record was captured
raw_valueNUMERIC(12,2)Original numeric value
statusVARCHAR(20)Record status
record_updates
ColumnTypeDescription
update_idPKINTUnique update identifier
record_idINTReferenced raw record
updated_atTIMESTAMPUpdate timestamp
corrected_valueNUMERIC(12,2)Replacement value, when supplied
Tablesentitiesraw_recordsrecord_updates
Interviewer

Your question is Transforming Data with SQL. 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.