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 Validation With Business Rules
00:00
5 left

SQL Validation With Business Rules

MediumSQL · PostgreSQL

Problem

Given a specific data table, calculate the expected output based on a set of conditional business rules.

Write a PostgreSQL query using data_records and conditional_rules. Apply the listed amount ranges and return the calculated decision and adjusted amount for every record, including records with no matching rule.

Output

  1. One row per record, with record_id, category, amount, decision, and adjusted_amount.
  2. Null amounts are REVIEW; negative amounts are INVALID with an adjusted amount of zero; unmatched non-null values are UNCLASSIFIED and retain their amount.
  3. Order by record_id ascending.

Schema

data_records
ColumnTypeDescription
record_idPKINTUnique identifier for the source record
categoryVARCHAR(20)Category used to select a conditional rule
amountDECIMAL(10,2)Value evaluated against the rule range
conditional_rules
ColumnTypeDescription
rule_idPKINTUnique identifier for the conditional rule
categoryVARCHAR(20)Category to which the rule applies
min_amountDECIMAL(10,2)Inclusive lower boundary for the rule
max_amountDECIMAL(10,2)Exclusive upper boundary for the rule
outcomeVARCHAR(20)Decision returned when the rule matches
multiplierDECIMAL(5,2)Factor applied to the source amount
Tablesdata_recordsconditional_rules
Interviewer

Your question is SQL Validation With Business Rules. 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.