Post Engagement Trends
Twitter ☯️ Medium SQL
Beginner Mode

Objective

Write a SQL query to calculate the 3-day rolling average of posts for each user.

Table Schema:

  • posts
Column Type Description
post_id INTEGER Unique identifier for each post
user_id INTEGER ID of the user who created the post
post_date DATE Date when the post was created
post_count INTEGER Number of posts created on that date by the user

Task Requirements:

  • Calculate a 3-day rolling average of posts for each user
  • The rolling average should include the current day and the 2 preceding days
  • Round the rolling average to 2 decimal places
  • Order results by user_id and post_date

Output columns: user_id, post_date, rolling_avg_3d

Examples

Example 1:

Input:

posts
post_countpost_datepost_iduser_id
52024-01-011101
32024-01-022101
72024-01-033101
22024-01-044101

Output:
post_daterolling_avg_3duser_id
2024-01-015101
2024-01-024101
2024-01-035101
2024-01-044101
Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →