Rank Doctors by Distinct Patients

Postgres Engine
Database Schema
Question (#76)
Rank doctors by the number of distinct patients they treated. Calculate the number of unique patients each doctor has seen. The returned results include the following columns: doctor_id, doctor_name (full name), unique_patients, rank. Sort the list by the total number of cases unique_patients in descending order, when multiple doctors share the same rank sorting by doctor_id in ascending order.
Expected Output
Query Editor
User Output Ready
Execute a query or press Ctrl+Enter to view results...
Databases & Questions
Hint
Count the distinct patients for each doctor, then rank those counts.
Official Solutions
Select a solution...