Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
Schema Design Scenario
00:00
5 left

Schema Design Scenario

HardSQL · PostgreSQL

Problem

Again, scenario of a schema for which I needed to design the whole schema?

Design a normalized relational schema for accounts, customers, account ownership, and account transactions, then write a query that validates the design by producing an account-level balance report. Include accounts without transactions and preserve accounts with no recorded owner.

Output

  1. One row per account with account_id, account_type, owner_names, balance, latest_transaction_date, and account_type_rank.
  2. Include every account, calculate credits as positive and debits or disbursements as negative, and use zero for accounts without transactions.
  3. Sort by account_type, descending balance, then account_id.

Schema

accounts
ColumnTypeDescription
account_idPKINTUnique account identifier
account_typeVARCHAR(20)Account classification
opened_dateDATEDate the account was opened
statusVARCHAR(20)Current account status
customers
ColumnTypeDescription
customer_idPKINTUnique customer identifier
customer_nameVARCHAR(100)Customer's full name
customer_statusVARCHAR(20)Current customer status
account_holders
ColumnTypeDescription
account_idPKINTReferenced account
customer_idPKINTReferenced customer
holder_roleVARCHAR(20)Customer's ownership role
added_dateDATEDate the customer was added
account_transactions
ColumnTypeDescription
transaction_idPKINTUnique transaction identifier
account_idINTReferenced account
transaction_typeVARCHAR(20)Credit, debit, or disbursement
amountNUMERIC(14,2)Nonnegative transaction amount
transaction_dateDATEDate of the transaction
descriptionVARCHAR(100)Optional transaction description
Tablesaccountscustomersaccount_holdersaccount_transactions
Interviewer

Your question is Schema Design Scenario. 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.