Calculate DAU/MAU ratio per user from products

Quick Overview

Write SQL to compute DAU/MAU ratio grouped by user from products, handling nulls and duplicates.

Walmart
Data Manipulation (SQL/Python)
Data Scientist
Walmart
Data Scientist
Phone Screen
Data Manipulation (SQL/Python)
Medium

11


Write SQL to compute DAU/MAU ratio grouped by user from products, handling nulls and duplicates.

Walmart data scientists track engagement with stickiness metrics such as DAU/MAU across the app and product pages. The interviewer is checking whether you can define daily and monthly activity precisely in SQL, deduplicate events, exclude bad rows, and join the two levels of aggregation correctly.

What the Interviewer Expects
  • Define DAU and MAU precisely, including the date and time zone used
  • Exclude rows with NULL user_id or activity date
  • Count distinct users so repeat events do not inflate counts
  • Join daily counts to the matching month's MAU correctly
  • Guard against division by zero and integer division
  • Explain how to interpret the ratio as a stickiness measure
Key Topics to Cover
DAU/MAU
COUNT DISTINCT
Date truncation
CTEs
Engagement metrics
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
  • How would you compute a rolling 28-day MAU instead of a calendar month?
  • How would you compute per-user stickiness, the share of days in a month a user was active?
  • How would bots or test accounts distort DAU/MAU and how would you filter them?
  • Why might DAU/MAU look high for a small, very engaged user base?
Sharpen Your Skills on Codemia

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

Practice SQL Problems
Sample Answer
Problem Understanding

To solve the problem of calculating the Daily Active Users (DAU) and Monthly Active Users (MAU) ratio for Walmart from product interactions, we need to focus on user activity data. The relevant data w...

Approach
  1. Select Data: Start by selecting the relevant columns from the 'user_activity' table, specifically user_id and activity_date.
  2. Calculate DAU: Group the data by activity_date and coun...

Submit Your Answer
Markdown supported

Related Questions