Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Readiness Trend Tiles for Wellness Dashboard

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Readiness Trend Tiles for Wellness Dashboard. Start with the requirements and the one table on the right.

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.

Problem

Business Context

You work on the analytics team for a wearable-health platform (think WHOOP/Oura-like) with 3M monthly active users. The product team is building an in-app “Readiness & Wellness Trends” dashboard that helps users understand whether their recovery is improving or declining. The dashboard needs a compact dataset that a BI tool (Looker/Tableau) can visualize as: (a) a daily readiness line chart, (b) a 7-day moving average line, and (c) a “trend” indicator (up/down/flat) comparing recent vs prior periods.

The data model is typical of consumer health: one row per user per day with readiness and a few wellness indicators. Users can have missing days (device not worn), and the dashboard should only consider days with a valid readiness score.

Task

Write a SQL query that produces a daily time series for each user over their most recent 14 days of data, including a 7-day moving average and a trend label that can be directly used for visualization.

Requirements

  1. Consider only rows where readiness_score is not NULL.
  2. For each user_id, find the latest metric_date available and return the 14 most recent days up to that date (not “last 14 calendar days”).
  3. Output one row per user_id and metric_date with:
    • readiness_score
    • sleep_hours
    • resting_hr
    • readiness_7d_ma: 7-row moving average of readiness (current day + previous 6 available days)
  4. Add trend_label computed per user as:
    • UP if avg readiness over the most recent 7 rows is >= prior 7 rows + 5 points
    • DOWN if it is <= prior 7 rows - 5 points
    • otherwise FLAT
  5. Order results by user_id, then metric_date ascending.

Schema

users
ColumnTypeDescription
user_idPKINTPrimary key for the user
signup_dateDATEDate the user created an account
countryVARCHAR(2)ISO country code
daily_wellness_metrics
ColumnTypeDescription
user_idINTUser identifier; references users.user_id
metric_dateDATELocal date of the measurement
readiness_scoreINT0–100 readiness score; NULL when no wearable data
sleep_hoursDECIMAL(4,2)Total sleep duration in hours
resting_hrINTResting heart rate (bpm)
Tablesdaily_wellness_metrics
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results