Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 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
Build my plan
Window Functions for Anomaly Streaks
00:00
5 left

Window Functions for Anomaly Streaks

MediumSQL · PostgreSQL

Problem

Write a complex SQL query using window functions to identify consecutive days of sensor anomalies.

Use the sensor_readings table. Return only anomaly streaks containing at least two consecutive calendar days.

Output

  1. One row per sensor anomaly streak
  2. Columns: sensor_id, streak_start, streak_end, consecutive_days
  3. Sort by sensor_id, then streak_start

Schema

sensor_readings
ColumnTypeDescription
reading_idPKINTUnique sensor reading identifier
sensor_idVARCHAR(20)Sensor identifier
reading_dateDATECalendar date of the reading
anomaly_typeVARCHAR(30)Detected anomaly category
anomaly_scoreNUMERIC(5,2)Severity score for the reading
is_anomalyBOOLEANWhether the reading is classified as anomalous
Tablessensor_readings
Interviewer

Your question is Window Functions for Anomaly Streaks. Start with the requirements and the one table 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.