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 unique province_id which links back to the patients table.

Important Concepts

  • Joins: You'll need to use a SQL JOIN to combine rows from patients and province_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

  1. Write your SQL query in the provided text editor.
  2. Run the query to see if it returns the expected output.
  3. Make sure your query is optimized and adheres to SQL best practices.
  4. Name of your first column must be "province_name". Name of your second column must be "patient_count"

Good luck!