Hospital Database Management System Oracle SQL
Hospital Database Management System Oracle SQL
sql 1/12
--2 Write a query in SQL to find the name of the nurse who are the head of t
--3 Write a query in SQL to obtain the name of the physicians who are the he
--4 Write a query in SQL to count the number of patients who taken appointme
--5 Write a query in SQL to find the floor and block where the room number 2
select blockfloor,blockcode,roomnumber
from room
where roomnumber=212;
select count(unavailable)
from room
where unavailable='f';
(select count(unavailable)
from room
where unavailable='t')
select *from avlbl;
--8 Write a query in SQL to obtain the name of the physician and the departm
--9 Write a query in SQL to obtain the name of the physicians who are traine
select employeeid,name
from physician
where employeeid in (select distinct physician
from trained_in);
--10 Write a query in SQL to obtain the name of the physicians with departme
on p.employeeid = aw.physician
inner join department d
on aw.department = d.department_id
where primaryaffiliation='f';
--11 Write a query in SQL to obtain the name of the physicians who are not a
--12 Write a query in SQL to obtain the name of the patients with their phys
--13 Write a query in SQL to find the name of the patients and the number of
--14 Write a query in SQL to count number of unique patients who got an appo
from appointment
group by examinationroom
having examinationroom='C';
--15 Write a query in SQL to find the name of the patients and the number of
--16 Write a query in SQL to find the name of the nurses and the room schedu
--17 Write a query in SQL to find the name of the patients who taken the app
on a.prepnurse = n.employeeid
where start_dt = '25-04-08';
--18 Write a query in SQL to find the name of patients and their physicians
--19 Write a query in SQL to find the name of the patients, their treating p
--20 Write a query in SQL to find the name of the patients who taken an adva
select p.ssn,
p.name as patient_name,
5.1 / 12 2023.06.24 13:34:22
Hospital Database Management System SQL ORCLPDB.sql 6/12
m.name as medicine_name
from patient p
left outer join appointment a
on p.ssn = a.patient
left outer join prescribes pr
on a.patient = pr.patient
left outer join physician ph
on pr.physician = ph.employeeid
left outer join medication m
on pr.medication = m.code
;
--22 Write a query in SQL to count the number of available rooms in each blo
--23 Write a query in SQL to count the number of available rooms in each flo
--24 Write a query in SQL to count the number of available rooms for each bl
from room
where unavailable='f'
group by blockcode,blockfloor
order by 1,2;
--25 Write a query in SQL to count the number of unavailable rooms for each
--26 Write a query in SQL to find out the floor where the maximum no of room
--27 Write a query in SQL to find out the floor where the minimum no of room
select blockfloor,count(unavailable)
from room
where unavailable = 'f'
group by blockfloor
having count(unavailable)=(select min(count(unavailable))
from room
where unavailable ='f'
group by blockfloor)
order by blockfloor;
--28 Write a query in SQL to obtain the name of the patients, their block, f
--29 Write a query in SQL to obtain the nurses and the block where they are
--31 Write a SQL query to obtain the names of all the physicians performed a
--32 Write a query in SQL to obtain the names of all the physicians, their
--33 Write a query in SQL to obtain the name and position of all physicians
--34 Write a query in SQL to obtain the name of all those physicians who com
--date of procedure, name of the patient on which the procedure had been app
select employeeid,
9.1 / 12 2023.06.24 13:34:22
Hospital Database Management System SQL ORCLPDB.sql 10/12
ph.position,
pr.name as procedure_name,
u.date_ as date_of_procedure,
p.name as patient_name,
ti.certificationexpires
from physician ph
left outer join undergoes u
on ph.employeeid = u.physician
left outer join patient p
on u.patient = p.ssn
left outer join trained_in ti
on u.procedure = ti.treatment
left outer join procedure pr
on ti.treatment = pr.code
where date_ > certificationexpires;
--35 Write a query in SQL to obtain the names of all the nurses who have eve
--36 Write a query in SQL to Obtain the names of all patients who has been p
--out primary care and the name of that physician
--37 Write a query in SQL to obtain the names of all patients who has been u
--physician who has carried out primary care
--38 Write a query in SQL to Obtain the names of all patients who had at lea
--out primary care
on p.pcp = ph.employeeid
where registered='t'
group by a.patient,p.name,ph.name
having count(start_dt) >=2;
--39 Write a query in SQL to Obtain the names of all patients whose primary
--department and name of that physician along with their primary care physic