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 Division and NULL Behavior
00:00
5 left

SQL Division and NULL Behavior

MediumSQL · PostgreSQL

Problem

Virtusa Data Platform runs SQL expression checks before deploying transformations. Write a PostgreSQL query that reports the outcome of four division expressions: 0 / NULL, NULL / 1, NULL / NULL, and 0 / 0.

The query must classify division by zero without executing an unsafe expression that would abort the statement.

Requirements

  1. Return only the four requested expression cases.
  2. Join each expression to its runtime profile.
  3. Return the expression label, operands, evaluated result, and status.
  4. Represent divisions involving NULL as a NULL result, and represent 0 / 0 as a division-by-zero error status.
  5. Order results in the requested expression order.

Schema

expression_cases
ColumnTypeDescription
case_idPKINTUnique expression test identifier
profile_idINTReferenced runtime profile
expression_labelVARCHAR(40)Human-readable arithmetic expression
numeratorNUMERICLeft operand of the division
denominatorNUMERICRight operand of the division
display_orderINTOrdering of the expression in the report
runtime_profiles
ColumnTypeDescription
profile_idPKINTUnique runtime profile identifier
profile_nameVARCHAR(50)Name of the execution profile
activeBOOLEANWhether the profile is currently active
Tablesexpression_casesruntime_profiles
Interviewer

Your question is SQL Division and NULL Behavior. 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.