About the “Hospital Formulary Drug Dispensation & Expenditure” SQL Problem
Business Scenario
Hospital pharmacy leadership is auditing pharmaceutical procurement costs across inpatient units. They need to aggregate expenditures per drug classification to pinpoint medications driving high clinical costs.
Expected Output & Criteria
Summary of pharmaceutical spending per drug category sorted by total cost.
Database Table Schema (PostgreSQL DDL)
PostgreSQL 16 WASMThis challenge executes directly against the following relational schema in your browser:
CREATE TABLE pharmacy_dispensations (
dispense_id INT PRIMARY KEY,
patient_id INT NOT NULL,
drug_category VARCHAR(50) NOT NULL,
units_dispensed INT NOT NULL,
unit_cost NUMERIC(8, 2) NOT NULL
);Target SQL Clauses & Operators
GROUP BYSUMCOUNTORDER BY
Want more Aggregations practice?
Explore the full syllabus of 12 exercises, syntax guides, and interview pitfalls.