Each Facebook Page's Top Post of the Week Including Ties
Last updated: November 29, 2026
Quick Overview
For every Facebook Page and calendar week, return the post or posts with the highest weighted engagement score, where score = reactions + 2 * comments + 3 * shares. If two posts tie, return both.
Meta
November 29, 20260
0
0 solved
For every Facebook Page and calendar week, return the post or posts with the highest weighted engagement score, where score = reactions + 2 * comments + 3 * shares. If two posts tie, return both.
Pages and creator analytics at Meta surface 'top post' modules, and the interviewer uses this to test whether you pick the ranking function that matches the business rule on ties. It also checks that you aggregate engagement before ranking.
What the Interviewer Expects
- Aggregates engagement events to one score per post before ranking
- Buckets posts into weeks with DATE_TRUNC on the post creation time
- Chooses RANK or DENSE_RANK because ties must be kept
- Partitions by page and week
- Explains how ROW_NUMBER would silently drop a tied post
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 return the top three posts per page per week, still keeping ties at the boundary?
- Should a post be credited to the week it was created or the week the engagement happened? Defend one.
- How would you normalize the score for Pages with very different follower counts?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
Tables:
posts(post_id, page_id, created_at)post_engagement_daily(post_id, ds, reactions, comments, shares), one row per post per day with activity.
I will credit all engagement to the week t...
Approach
- Sum engagement per post across all days.
- Left join to
postsso zero-engagement posts get a score of 0. - Compute the weighted score, bucket by
DATE_TRUNC('week', created_at). RANK()wi...