Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
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
Sign up free to run your codeLog inLn 1
Run your query to see results here.