Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Defect Counts Before vs After Migration
00:00
5 left

Defect Counts Before vs After Migration

MediumSQL · PostgreSQL

Problem

Write a SQL query to compare defect counts before and after a database migration.

Use the provided migrations and defects tables. Treat defects detected before the migration date as before-migration defects, and defects detected on or after that date as after-migration defects.

Output

  1. One row per migration, including migrations with no matching defects
  2. Columns: migration_id, system_name, migration_date, defects_before, defects_after, and count_change
  3. Sort by migration_date ascending, then migration_id ascending

Schema

migrations
ColumnTypeDescription
migration_idPKINTUnique migration identifier
system_nameVARCHAR(100)System affected by the migration
migration_dateDATEDate the migration occurred
defects
ColumnTypeDescription
defect_idPKINTUnique defect identifier
system_nameVARCHAR(100)System where the defect was detected
detected_atDATEDate the defect was detected
statusVARCHAR(30)Current defect status
Tablesmigrationsdefects
Interviewer

Your question is Defect Counts Before vs After Migration. 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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.