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
Optimize Complex Analytics in Warehouses
00:00
5 left

Optimize Complex Analytics in Warehouses

HardSQL · PostgreSQL

Problem

How would you handle query optimization for complex analytics workloads on cloud data warehouses like Snowflake or BigQuery?

Using the supplied PostgreSQL tables, write a query that demonstrates an efficient analytics pattern over a fixed three-month period. Include only completed encounters within the period, preserve facilities with no activity, and produce monthly metrics with a rolling three-month charge total.

Output

  1. One row per facility and month from January through March 2025.
  2. Columns: facility_name, month_start, encounter_count, total_units, total_charges, and rolling_three_month_charges.
  3. Include facilities with no qualifying encounters as zero-valued rows, ordered by facility name and month.

Schema

facilities
ColumnTypeDescription
facility_idPKINTUnique facility identifier
facility_nameVARCHAR(100)Facility name
regionVARCHAR(50)Geographic region
encounters
ColumnTypeDescription
encounter_idPKINTUnique encounter identifier
patient_idINTPatient identifier
facility_idINTFacility where the encounter occurred
encounter_dateTIMESTAMPEncounter timestamp
statusVARCHAR(20)Encounter status
payerVARCHAR(30)Payer category
encounter_services
ColumnTypeDescription
service_idPKINTUnique service line identifier
encounter_idINTRelated encounter identifier
service_codeVARCHAR(20)Service classification code
unitsINTNumber of billed service units
charge_amountNUMERIC(12,2)Charge amount for the service line
Tablesfacilitiesencountersencounter_services
Interviewer

Your question is Optimize Complex Analytics in Warehouses. 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.