Posting Activity Gap
Meta 👶 Easy SQL
Beginner Mode

Objective

Write a SQL query to calculate the number of days between each user's first and last post in 2021 for users who posted at least twice during that year.

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 DATETIME Date and time when the post was created

Task Requirements:

  • Filter only posts from the year 2021
  • Include only users who posted at least twice in 2021
  • Calculate the number of days between each user's first and last post
  • Return the user ID and the days between their posts

Output columns: user_id, days_between

Examples

Example 1:

Input:

posts
post_datepost_iduser_id
2021-01-15 10:00:001101
2021-01-20 11:00:002101
2021-02-01 12:00:003102
2021-03-01 13:00:004102
2021-04-15 14:00:005103

Output:
days_betweenuser_id
5101
28102
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 →