Daily Count of Users Active Five of the Last Seven Days

Last updated: November 29, 2026

Quick Overview

For every calendar day, count how many Facebook users were active on at least five of the seven days ending that day, including users who happen to be inactive on the day itself. Produce a daily series for the last 60 days.

Meta
Data Manipulation (SQL/Python)
Data Scientist
Meta
November 29, 2026
Data Scientist
Onsite
Data Manipulation (SQL/Python)
Hard

0

0

0 solved


For every calendar day, count how many Facebook users were active on at least five of the seven days ending that day, including users who happen to be inactive on the day itself. Produce a daily series for the last 60 days.

A harder SQL question in Meta's core growth analytics loop, where the share of 'L5+' users is a health metric for engagement depth. The interviewer checks whether you realize that windowing over a user's active rows misses days they were inactive, and whether you can expand rows to fix it.

What the Interviewer Expects
  • Deduplicate to distinct user-days
  • Recognize that a per-row window cannot evaluate days a user was inactive
  • Expand each active day to the seven as-of dates it counts toward
  • Count active days per user per as-of date and threshold at five
  • Trim the edges where the window is incomplete
Key Topics to Cover
rolling windows
row expansion
UNNEST SEQUENCE
L7 metrics
engagement depth
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • What is the cost of the 7x expansion and how would you reduce it?
  • How would you produce the full L1 to L7 distribution per day?
  • How would you do this with a bitmask per user per day?
  • How would you make it incremental daily?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

daily_active(user_id, ds), possibly with duplicates. For as-of date D, the window is D-6 through D. A user counts if they have five or more distinct active dates in that window. Output: as_of, cou...

Approach

A window function over a user's own rows only produces output on days that user was active, so a user active Mon to Fri and inactive Saturday would be missed for Saturday. Instead, I expand: each acti...


Submit Your Answer
Markdown supported