create table hospitals (
hospital_id int NOT NULL PRIMARY KEY,
name varchar(20) NOT NULL,
address varchar(30) NOT NULL
);
create table departments (
dept_id int not null PRIMARY key,
hospital_id int not null ,
name varchar(20),
number_of_beds int,
info varchar(50),
CONSTRAINT FK_PersonOrder FOREIGN KEY (hospital_id) REFERENCES hospitals(hospital_id)
);
create table patients (
patient_id int NOT NULL,
dept_id int not null,
name varchar(15) not null,
address varchar(20) not null,
Hospitalization_date date,
ward int,
CONSTRAINT FK_PatientDept FOREIGN KEY(dept_id) REFERENCES departments(dept_id)
)
select hospital_id, count(departments.dept_id) as number_of_departments, count(patients.ward) as number_of_ward, count(patients.patient_id) as number_of_patients
from hospitals
left join departments
on hospitals.hospital_id=departments.hospital_id
left join patients
on departments.dept_id patients.dept_id= patients.dept_id
GROUP BY hospital_id;