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
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
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- 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 ProblemsSample 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
- Select Data: Start by selecting the relevant columns from the 'user_activity' table, specifically
user_idandactivity_date. - Calculate DAU: Group the data by
activity_dateand coun...