Counting Patients by Province in Descending Order: An SQL Lab
Easy
3
62.5% Acceptance
Your task is to write an SQL query to display the total number of patients for each province. The results should be ordered in descending order based on the number of patients.
Database Tables
patients
: Contains information about patients.province_names
: Contains details about provinces, including a uniqueprovince_id
which links back to thepatients
table.
Important Concepts
- Joins: You'll need to use a SQL JOIN to combine rows from
patients
andprovince_names
. - Aggregation: The use of
COUNT
will be necessary to sum up the number of patients per province. - Sorting: The
ORDER BY
clause will help you sort the results in descending order.
Instructions
- Write your SQL query in the provided text editor.
- Run the query to see if it returns the expected output.
- Make sure your query is optimized and adheres to SQL best practices.
- Name of your first column must be "province_name". Name of your second column must be "patient_count"
Good luck!