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 5 Categories by Total Count
00:00
5 left

Top 5 Categories by Total Count

MediumSQL · PostgreSQL

Problem

University of Kansas Medical Center reporting needs a summary of transaction volume by category. Write a PostgreSQL query that identifies the five categories with the most completed transactions during calendar year 2024.

Requirements

  1. Include every category in the aggregation, including categories with no qualifying transactions.
  2. Count only transactions with status = 'Completed' and a transaction_date in 2024.
  3. Return the category name and transaction count, ordered from highest to lowest count, with category name ascending as the tie-breaker.
  4. Return only the top five categories.

Schema

transaction_categories
ColumnTypeDescription
category_idPKINTPrimary key for the category
category_nameVARCHAR(100)KUMC transaction category name
is_activeBOOLEANWhether the category is currently active
transactions
ColumnTypeDescription
transaction_idPKINTPrimary key for the transaction
category_idINTAssigned transaction category
statusVARCHAR(20)Transaction processing status
transaction_dateDATEDate the transaction was recorded
amountDECIMAL(12,2)Illustrative transaction amount
Tablestransaction_categoriestransactions
Interviewer

Your question is Top 5 Categories by Total Count. 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.