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 Consecutive Anomalous Days
00:00
5 left

SQL Consecutive Anomalous Days

MediumSQL · PostgreSQL

Problem

Write a SQL query using SQL window functions to identify consecutive days of anomalous email sending behavior for a given user.

Use the daily email activity records for user_id = 101. Treat rows where is_anomalous is true as anomalous, and return only streaks containing at least two consecutive calendar days.

Output

  1. One row per anomalous streak
  2. Columns: user_id, streak_start, streak_end, and anomalous_days
  3. Order by streak_start ascending

Schema

email_sending_daily
ColumnTypeDescription
record_idPKINTUnique daily activity record identifier
user_idINTIdentifier of the email-sending user
activity_dateDATECalendar date of the user's email activity
sent_countINTNumber of emails sent on the date
is_anomalousBOOLEANWhether the daily sending behavior was classified as anomalous
Tablesemail_sending_daily
Interviewer

Your question is SQL Consecutive Anomalous Days. 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.