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 for Monthly Facility Usage
00:00
5 left

SQL for Monthly Facility Usage

MediumSQL · PostgreSQL

Problem

Stanford University wants to understand which campus facilities are used most often by different student cohorts. Write a PostgreSQL query that ranks facilities by completed utilization events for each month and student cohort.

Requirements

  1. Join usage events to Stanford students and campus facilities.
  2. Include only completed events from January and February 2024, excluding rows with no student cohort.
  3. Aggregate utilization counts by calendar month, cohort year, and facility.
  4. Return the top five facilities per month and cohort, using utilization count descending and facility name ascending as the deterministic tie-breaker.
  5. Return results ordered by month, cohort year, rank, and facility name.

Schema

students
ColumnTypeDescription
student_idPKINTUnique Stanford student identifier
student_nameVARCHAR(100)Student full name
cohort_yearINTYear the student entered Stanford University
campus_facilities
ColumnTypeDescription
facility_idPKINTUnique facility identifier
facility_nameVARCHAR(150)Official Stanford campus facility name
facility_usage
ColumnTypeDescription
usage_idPKINTUnique facility usage event identifier
student_idINTStudent associated with the usage event
facility_idINTFacility associated with the usage event
used_atTIMESTAMPTimestamp when the facility was used
statusVARCHAR(20)Usage event status
Tablesstudentscampus_facilitiesfacility_usage
Interviewer

Your question is SQL for Monthly Facility Usage. 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.