Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.