Sei sulla pagina 1di 1

1

2 #QUERIES
3 #QUERY 1 Give Patient Name, duration of dtay at the hospital and balance due.
4 SELECT i.invoiceNumber,CONCAT(p.FirstName,' ', p.LastName) AS PatientName,
DATEDIFF(pr.checkoutDate,pr.CheckinDate) AS StayDuration, (i.totalAmount-i.amountPaid)
AS BalanceDue
5 FROM patient p JOIN patientRecord pr
6 ON p.patientID=pr.patientID
7 JOIN patientInvoice i
8 ON p.patientID=i.patientid;
9
10 #Query 2 Number of female patients
11 SELECT COUNT(PatientID) AS NumberOfFemalePatients
12 FROM patient
13 Where Gender='F'
14 GROUP BY Gender;
15
16 #Query 3 Name and number of patients their balance due with Contact information
17 SELECT p.patientID, CONCAT_WS(' ', p.FirstName, p.LastName) As Patient_Name,
18 (i.TotalAmount-i.AmountPaid) AS Balance_Due,
19 p.PhoneNumber AS Contact_Number,CONCAT_WS(' ',p.address1,
20 p.Address2, p.City, p.State, p.ZipCode) AS Patient_Address
21 FROM patient p JOIN patientinvoice i
22 ON p.PatientID=i.PatientID
23 WHERE(i.TotalAmount-i.AmountPaid)>0;
24
25 #Query 4 Name of the Patient, Room Number, Attending Nurses
26
27 SELECT Y.patientID,CONCAT_WS(' ', pt.firstName,pt.LastName) AS
PatientName,Y.roomNumber,AttendingNurse, Y.employeeID
28 FROM patient pt JOIN
29 (SELECT patientid, RoomNumber,CONCAT_WS(' ',e.FirstName, e.LastName) AS AttendingNurse,
T.employeeID
30 FROM employee e JOIN
31 (SELECT employeeID, nr.RoomNumber, r.PatientID
32 FROM nursegovernsroom nr JOIN rooms r
33 ON nr.RoomNumber=r.RoomNumber) T
34 ON e.EmployeeID=T.employeeID) Y
35 ON pt.patientID=Y.patientID
36 ORDER BY Y.roomNumber;
37
38 #Query 5 Using VIEW
39 SELECT * FROM patient_emergency_contact_information
40 WHERE patient_emergency_contact_information.PatientID=8;
41
42 #Query 6 Number of patients each doctor is responsible for sorted by doctor last name.
43 Select concat(e.firstname, ' ', e.lastname) as DoctorName, Count(*) as NumberOfPatients
from patient p join patient_has_doctor phd On
44 p.PatientID = phd.PatientID join employee e On phd.doctoriD = e.EmployeeID Group by
phd.DoctorID Order by e.lastname;
45
46 #Query 7 Number of vacant rooms.
47 select count(*) as NumberofVacantRooms from rooms where patientID is null group by
patientID;
48
49 #Query 8 Total Number of Doctors and Number of Nurses
50 select employeetype, count(*) as Count from employee group by employeetype;
51
52
53
54

Potrebbero piacerti anche