Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Categories With Window Functions
00:00
5 left

Top Categories With Window Functions

MediumSQL · PostgreSQL

Problem

The LexisNexis legal research platform needs a monthly view of which content categories attract the most reader activity. Write a PostgreSQL query that identifies the highest-performing content categories for each month in Q1 2025.

Requirements

  1. Join content events to content items and include only view events from January through March 2025.
  2. Aggregate total views and average engagement time by month and content category, excluding uncategorized content.
  3. Use a window function to rank categories within each month and return every category tied for first place.

Schema

content_items
ColumnTypeDescription
content_idPKINTUnique content identifier
titleVARCHAR(200)Content title
categoryVARCHAR(80)Content category
content_events
ColumnTypeDescription
event_idPKINTUnique event identifier
content_idINTReferenced content item identifier
event_dateDATEDate of user activity
event_typeVARCHAR(20)Type of user activity
engagement_secondsINTSeconds spent during the event
Tablescontent_itemscontent_events
Interviewer

Your question is Top Categories With Window Functions. Start with the requirements and the two tables in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePostgreSQL
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.