I’m working RWFD emergency room dataset, which includes patient’s race and what department they were referred to. I’m trying to show which department each race (7 total) is most commonly referred to, with the stipulation that department_referral is not ‘None’.
Dataset: https://data.world/markbradbourne/rwfd-real-world-fake-data/workspace/file?filename=Hospital+ER.csv
Problem with what I have tried: I can’t order by most_referrals and LIMIT 7 as this will show data for the more common races. For example, patient_race of White and African American show up twice within the top 7 rows.
What I tried:
SELECT patient_race, department_referral, COUNT(department_referral) as most_referrals
FROM ed
WHERE department_referral != 'None'
GROUP BY 1, 2
ORDER BY most_referrals DESC
LIMIT 7
;
2
Answers
You can try window function like this,