Quick Overview

This question evaluates proficiency in SQL data aggregation and time-based event summarization, focusing on counting and grouping user-generated records to measure recent activity.

Identify Top Contributors by Recent Post Count

Company: LinkedIn

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: medium

Interview Round: Technical Screen

posts +----+---------+---------------------+ | id | user_id | created_at | +----+---------+---------------------+ | 1 | 101 | 2023-09-01 10:00:00 | | 2 | 102 | 2023-09-01 11:00:00 | | 3 | 101 | 2023-09-02 09:30:00 | | 4 | 103 | 2023-09-02 12:45:00 | | 5 | 101 | 2023-09-03 14:20:00 | +----+---------+---------------------+ ##### Scenario A social media platform wants to list how many posts each user created in the last 30 days to spot top contributors. ##### Question Given table posts(id, user_id, created_at), write a SQL query that returns user_id and post_count for the past 30 days, ordered by post_count DESC. ##### Hints Filter by created_at >= current_date - interval '30 days', GROUP BY user_id, ORDER BY count desc.

Overview: This question evaluates proficiency in SQL data aggregation and time-based event summarization, focusing on counting and grouping user-generated records to measure recent activity.

Given table posts(id, user_id, created_at), write a SQL query that returns user_id and post_count for the past 30 days, ordered by post_count DESC.

Tables

posts(id INTEGER, user_id INTEGER, created_at TIMESTAMP)

Hints

  1. Filter to the last 30 days: created_at >= CURRENT_DATE - INTERVAL '30 days'.
  2. Group by user_id and use COUNT(*) to compute post_count.
LinkedInData ScientistmediumData Manipulation (SQL/Python)

Identify Top Contributors by Recent Post Count

Given table posts(id, user_id, created_at), write a SQL query that returns user_id and post_count for the past 30 days, ordered by post_count DESC.

Expected Output

A list of users with how many posts they created in the last 30 days, ordered by post_count descending. For the provided sample data (assuming all rows fall within the last 30 days), the counts are computed across those rows.

Tables

posts
posts
ColumnType
idINTEGER
user_idINTEGER
created_atTIMESTAMP

Comments (0)

No comments yet. Be the first to comment!

Submit your answer

Approved first answer today earns 30 XP
Bold⌘BItalic⌘IInline code⌘`Bullet listTab to nest (○ ■)Numbered listTab to nest (a. i.)QuoteCode block
Formatting help
Language
Run code to see results here.

Browse More Questions