Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
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 feedbackSuccess 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 Users SQL Query
00:00
5 left

Top Users SQL Query

MediumSQL · PostgreSQL

Problem

Write an SQL query to find the top 3 users based on their interactions on a given day.

Use 2025-02-14 as the given day. Count only countable interaction types and interactions that are not deleted. Rows with a NULL interaction timestamp are ignored.

Output

  1. Return up to three rows, one per user.
  2. Include user_id, username, interaction_count, and rank.
  3. Order by rank ascending. Break equal interaction counts by user_id ascending.

Schema

users
ColumnTypeDescription
user_idPKINTEGERUnique user identifier
usernameVARCHAR(100)User display name
interaction_types
ColumnTypeDescription
interaction_type_idPKINTEGERUnique interaction type identifier
interaction_type_nameVARCHAR(80)Name of the interaction type
is_countableBOOLEANWhether this interaction type contributes to user counts
interactions
ColumnTypeDescription
interaction_idPKINTEGERUnique interaction identifier
user_idINTEGERUser associated with the interaction
interaction_type_idINTEGERType associated with the interaction
occurred_atTIMESTAMPTimestamp when the interaction occurred
is_deletedBOOLEANWhether the interaction has been deleted
Tablesusersinteractionsinteraction_types
Interviewer

Your question is Top Users SQL Query. Start with the requirements and the three 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.