Join messages and impressions to find rolling 7-day average
Last updated: October 31, 2025
Quick Overview
Write a query joining messages and rides to produce the combined rolling 7-day average.
Pinterest
Data Manipulation (SQL/Python)
Data Scientist
Data Scientist
Phone Screen
Data Manipulation (SQL/Python)
Medium
1
7
1,781 solved
Write a query joining messages and rides to produce the combined rolling 7-day average.
This question from Pinterest's Phone Screen tests practical data skills. The interviewer wants to see clean, efficient queries that handle edge cases like NULLs, duplicates, and large datasets.
What the Interviewer Expects
- Use advanced SQL features: window functions, CTEs, subqueries
- Write efficient queries that avoid common performance pitfalls
- Handle complex data transformations with multiple joins and aggregations
- Discuss indexing strategy and query optimization
- Address data quality issues: duplicates, missing values, outliers
Key Topics to Cover
Aggregate functions and GROUP BY
Data cleaning and transformation
Index optimization and query performance
Subqueries and correlated subqueries
Common Table Expressions (CTEs)
Window functions (ROW_NUMBER, RANK, LAG, LEAD)
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 handle slowly changing dimensions in this scenario?
- How would you handle this if the data was spread across multiple databases?
- What indexes would you create to support this query?
- How would you validate the correctness of your query results?
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
The goal of this query is to calculate the rolling 7-day average of messages sent and rides taken on Pinterest. We are working with two tables: messages and rides. The messages table contains re...
Approach
- Data Inspection: First, check the structure of both
messagesandridestables to identify relevant columns for joining (e.g., user_id, timestamp). - Join Tables: Use a LEFT JOIN to co...
Submit Your Answer
Markdown supported