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
Profile Missing Activity Values by Site
00:00
5 left

Profile Missing Activity Values by Site

MediumSQL · PostgreSQL

Problem

You are given a dataset with missing values; how do you proceed?

Write a SQL query that profiles missing values in NHS activity records by site. Include sites with no activity records and treat missing site names as Unnamed site.

Output

  1. One row per NHS site.
  2. Columns: site_code, site_name, total_records, missing counts for each activity field, missing_value_count, and missing_value_rate_pct.
  3. Include sites with zero activity records, and order by site_code ascending.

Output details

  • Return columns in this order: site_code, site_name, total_records, missing_activity_date, missing_completed_attendances, missing_cancellations, missing_postcode, missing_value_count, missing_value_rate_pct.
  • Count only actual activity records in total_records and missing-field counts, excluding the placeholder row for sites with no activity.
  • Calculate missing_value_count as the sum of the four activity-field missing counts.
  • Calculate missing_value_rate_pct as missing values divided by total_records * 4, multiplied by 100.
  • Round missing_value_rate_pct to two decimal places and return 0.00 when total_records is zero.
  • Group rows by the combination of site_code and site_name, allowing multiple rows with the same site_code when names differ.

Schema

nhs_sites
ColumnTypeDescription
site_idPKINTEGERUnique NHS site identifier
site_codeVARCHAR(20)Short NHS site code
site_nameVARCHAR(100)Display name of the NHS site
nhs_activity
ColumnTypeDescription
activity_idPKINTEGERUnique activity record identifier
site_idINTEGERNHS site associated with the activity
activity_dateDATEDate of the recorded activity
completed_attendancesINTEGERNumber of completed attendances
cancellationsINTEGERNumber of cancellations
postcodeVARCHAR(30)Postcode associated with the activity
Tablesnhs_sitesnhs_activity
Interviewer

Your question is Profile Missing Activity Values by Site. 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.