Menu

1 / 2

Analyzing doctors data using SQL

DEV Community: postgres·Dennis Wachira·11 days ago
#wZbuEYWO
#devtopostgresql#devto#dev#doctor_name#group
Reading 0:00
15s threshold

Today, I focused on analyzing hospital records from a doctor's perspective. Instead of writing queries just to retrieve rows, I started asking meaningful questions that someone in hospital management might actually ask. I explored questions such as:

How many doctors are available in the hospital?

select pr.doctor_name from patient_records pr

group by doctor_name

order by doctor_name asc;

How many patients has each doctor treated?

select pr.doctor_name, count(*) as n_patients

from patient_records pr

group by doctor_name

order by doctor_name asc;

Which patients were treated by a specific doctor?

select pr.patient_id, pr.patient_name from patient_records pr

where pr.doctor_name ilike 'Dr. Chebet'

group by patient_id;

How many male and female patients did a particular doctor treat?

select gender, count (*) as n_patients

from patient_records pr

where doctor_name ilike 'Dr.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.