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 10% Users Query
00:00
5 left

Top 10% Users Query

MediumSQL · PostgreSQL

Problem

Given a table of user interactions, write a query to identify the top 10% of users based on their active search queries over the last 30 days.

Count only interactions that are searches, are marked active, have a non-null query, and occurred within the rolling 30-day period. Include users with at least one qualifying query.

Output

  1. One row for each selected user.
  2. Columns: user_id, active_search_queries, and decile.
  3. Return the highest-activity decile, ordered by active_search_queries descending and user_id ascending to break ties.

Schema

user_interactions
ColumnTypeDescription
interaction_idPKINTUnique interaction identifier
user_idINTIdentifier of the user who generated the interaction
interaction_typeVARCHAR(50)Type of interaction, such as search or message
is_activeBOOLEANWhether the interaction is active
query_textTEXTSearch text entered by the user
occurred_atTIMESTAMPTimestamp when the interaction occurred
Tablesuser_interactions
Interviewer

Your question is Top 10% Users Query. Start with the requirements and the one table 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.