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 Query for Test Data
00:00
5 left

SQL Query for Test Data

MediumSQL · PostgreSQL

Problem

Can you write a SQL query to extract specific test data and explain the expected output?

For this exercise, return completed Lead tests for Water samples collected during January 2025. Include the requested result classification and exclude records outside the date range or matching criteria.

Output

  1. One row per qualifying test result with accession_code, collection_date, test_name, result_value, result_unit, and assessment.
  2. Classify values above 0.010 as Above action level, values at or below 0.010 as Within action level, and NULL values as Not available.
  3. Order by collection_date, then accession_code.

Schema

test_samples
ColumnTypeDescription
sample_idPKINTUnique laboratory sample identifier
accession_codeVARCHAR(20)External sample accession code
client_nameVARCHAR(100)Client associated with the sample
collected_atTIMESTAMPTimestamp when the sample was collected
matrix_typeVARCHAR(30)Sample matrix, such as Water or Soil
test_results
ColumnTypeDescription
result_idPKINTUnique test result identifier
sample_idINTSample associated with the test result
test_nameVARCHAR(50)Analyte or laboratory test name
result_valueNUMERIC(10,4)Measured test value
result_unitVARCHAR(20)Unit for the measured value
statusVARCHAR(20)Processing status of the result
reported_atTIMESTAMPTimestamp when the result was reported
Tablestest_samplestest_results
Interviewer

Your question is SQL Query for Test Data. 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.