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
SQL: Top Active Doctors by Specialty
00:00
5 left

SQL: Top Active Doctors by Specialty

MediumSQL · PostgreSQL

Problem

Doximity wants to identify the most active doctors in each medical specialty based on activity recorded in the Doximity platform. Assume the evaluation date is 2025-02-15.

Write a PostgreSQL query to return the top three doctors in every specialty based on the number of activity events during the 30-day period ending on the evaluation date.

Requirements

  1. Include doctors with zero activity during the period, if they are assigned to a specialty.
  2. Count only events from 2025-01-17 through 2025-02-15, inclusive.
  3. Rank doctors independently within each specialty by activity count descending.
  4. Break ties deterministically using doctor_id ascending and return no more than three doctors per specialty.
  5. Return specialty, doctor, activity count, and rank, ordered by specialty and rank.

Schema

doctors
ColumnTypeDescription
doctor_idPKINTUnique Doximity doctor identifier
full_nameVARCHAR(150)Doctor's full name
specialties
ColumnTypeDescription
specialty_idPKINTUnique medical specialty identifier
specialty_nameVARCHAR(100)Medical specialty name
doctor_specialties
ColumnTypeDescription
doctor_idINTReferences doctors.doctor_id
specialty_idINTReferences specialties.specialty_id
activity_events
ColumnTypeDescription
event_idPKINTUnique activity event identifier
doctor_idINTReferences doctors.doctor_id; null for unattributed activity
occurred_atTIMESTAMPTimestamp when the activity occurred
event_typeVARCHAR(50)Type of Doximity activity
Tablesdoctorsspecialtiesdoctor_specialtiesactivity_events
Interviewer

Your question is SQL: Top Active Doctors by Specialty. Start with the requirements and the four 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.