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: Complex Expression Result
00:00
5 left

SQL: Complex Expression Result

MediumSQL · PostgreSQL

Problem

HCA Healthcare's authorization audit needs a derived score for each completed request code. For a code such as 367, calculate 3^1 + 6^2 + 7^3 = 382, where each digit is raised to its one-based position.

Write a PostgreSQL query that joins HCA request, patient, and facility data, calculates the score, and ranks requests within each active facility.

Requirements

  1. Include only requests with status = 'Completed', an active facility, and a three-digit numeric request_code.
  2. Split each code into digits and raise each digit to its one-based position.
  3. Return the request, patient, facility, calculated score, and descending score rank within the facility.
  4. Use CTEs and a window function, and sort by facility name, score descending, and request ID.

Representative data

Schema

authorization_requests
ColumnTypeDescription
request_idPKINTUnique authorization request identifier
patient_idINTReferenced patient
facility_idINTReferenced HCA Healthcare facility
request_codeVARCHAR(20)Authorization code to score
statusVARCHAR(20)Current request status
patients
ColumnTypeDescription
patient_idPKINTUnique patient identifier
patient_nameVARCHAR(100)Patient display name
facilities
ColumnTypeDescription
facility_idPKINTUnique facility identifier
facility_nameVARCHAR(120)HCA Healthcare facility name
is_activeBOOLEANWhether the facility is active for reporting
Tablesauthorization_requestspatientsfacilities
Interviewer

Your question is SQL: Complex Expression Result. 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.