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
ExperiencesCoaching
New
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
Get started
Nulls and Precision in SQL
00:00
5 left

Nulls and Precision in SQL

MediumSQL · PostgreSQL

Problem

How would you handle null values and data type formatting, including ensuring precision in output, in a complex reporting query for HackerRank?

Use the provided HackerRank challenge, domain, and submission data. Include active challenges even when they have no submissions, and represent missing values consistently.

Output

  1. One row per active challenge, ordered by challenge_id ascending.
  2. Return challenge_id, challenge_name, domain_name, total_submissions, average_score, pass_rate_pct, and average_score_display.
  3. Use zero-valued numeric metrics when no applicable submissions exist, and show domain Unassigned when the domain is missing.

Output details

  • Round average_score and pass_rate_pct to two decimal places and return them with two decimal places of numeric precision.
  • Count every submission in total_submissions, including submissions whose score is NULL.
  • Compute average_score from non-NULL scores only.
  • Define pass_rate_pct as passed submissions divided by submissions with non-NULL scores, multiplied by 100, rounded to two decimals.
  • Count a submission with status passed in the pass-rate numerator even when its score is NULL.
  • Format average_score_display with exactly two decimal places and no leading padding.

Schema

challenges
ColumnTypeDescription
challenge_idPKINTUnique HackerRank challenge identifier
challenge_nameVARCHAR(120)Challenge display name
domain_idINTOptional associated domain
is_activeBOOLEANWhether the challenge is currently active
domains
ColumnTypeDescription
domain_idPKINTUnique domain identifier
domain_nameVARCHAR(80)Challenge domain name
submissions
ColumnTypeDescription
submission_idPKINTUnique submission identifier
challenge_idINTChallenge associated with the submission
scoreNUMERIC(5,2)Submission score, which may be missing
statusVARCHAR(20)Submission result status
Tableschallengesdomainssubmissions
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the three tables are in the Question tab.

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.