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
SQL Joins and Aggregates Verification
00:00
5 left

SQL Joins and Aggregates Verification

MediumSQL · PostgreSQL

Problem

How would you write a query using JOINs, GROUP BY, and aggregate functions to verify database states?

Use the provided expected-state and actual-record tables. Identify whether each expected state is verified, mismatched, or missing, and also report actual states that were not expected.

Output

  1. One row per state key found in either table.
  2. Include the state identifiers, expected count and total, actual count and total, and a verification_status column.
  3. Sort by object_type, object_key, and check_id, with missing check IDs last.

Schema

expected_state_checks
ColumnTypeDescription
check_idPKINTUnique expected-state check identifier
object_typeVARCHAR(50)Category of the state being verified
object_keyVARCHAR(100)Identifier for the state within its category
expected_countINTExpected number of actual records
expected_totalNUMERIC(12,2)Expected sum of record amounts
actual_state_records
ColumnTypeDescription
record_idPKINTUnique actual record identifier
object_typeVARCHAR(50)Category of the actual state
object_keyVARCHAR(100)Identifier for the actual state
amountNUMERIC(12,2)Amount contributed by the actual record
Tablesexpected_state_checksactual_state_records
Interviewer

Your question is SQL Joins and Aggregates Verification. 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.