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 NULL Handling

MediumSQL & Data Manipulation00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL NULL Handling. Take a moment with it on the right.

Talk me through your thinking if you like. When you're confident, submit your answer and I'll grade it like a real screen (7/10 or better passes).

You need to log in / sign up to chat or submit.

Problem

Xylem builds water-treatment equipment, and a field-engineer dashboard queries sensor readings from pump stations. The query below is supposed to flag stations with a missing or offline flow-rate reading, but the numbers don't match what field engineers see on site.

CREATE TABLE pump_stations (
    station_id INT PRIMARY KEY,
    pump_name VARCHAR(80),
    location_note VARCHAR(120)  -- nullable, filled in only for stations with special access instructions
);

CREATE TABLE sensor_readings (
    reading_id INT PRIMARY KEY,
    station_id INT,
    flow_rate_gpm NUMERIC(8,2),  -- nullable when a sensor fails to report
    status VARCHAR(20),          -- nullable when a station has never checked in
    recorded_at TIMESTAMP
);

SELECT
    ps.pump_name || ' - ' || ps.location_note AS display_label,
    AVG(sr.flow_rate_gpm) AS avg_flow_rate,
    COUNT(*) AS reading_count
FROM pump_stations ps
JOIN sensor_readings sr ON sr.station_id = ps.station_id
WHERE sr.flow_rate_gpm = NULL
   OR sr.status <> 'Offline'
GROUP BY ps.pump_name, ps.location_note;

What is wrong with this query's handling of NULLs, and how would you fix it?