Practical 7
Practical 7
QUERIES:
1. Display Disease and doctor_Name of Pateint with ID P2.
2. Display ID, Name, Gender, Disease and Admit_Date of all Female Patients.
3. Calculate Room_Charges to be paid.
4. Search all Pateints under treatment of doctor Shariq Hameed.
5. Display Second_Highest_slary among Doctors.
6. Display recods of patients with particular disease.
7. Display recods of patients with min room charges.
8. Delete pateints record admitted on 1-Apr-23.
9. Update any patient’s status.
PROCEDURE:
Table Design:
TABLE 1: PATIENT
Open the Table PATIENT and and enter the records and then close this tab.
TABLE 2: PATIENT_STATUS
Open table PATIENT_STATUS and enter the records and close this tab.
TABLE 3: DOCTOR_PROFILE:
Goto menu bar then select create → Table design.
Enter Field names with suitable data type.
Assign Doctor_ID as Primary key of table 2:DOCTOR_PROFILE.
Save the table by ctrl+s.
Open table DOCTOR_PROFILE and enter the records and close this tab.
RELATIONSHIPS:
Now create Relationship between the tables , go to database tools in the tool bar then go to relationships and add
all three tables and drag the fields to relate them from one table to the other.
QUERY # 1:
OUTPUT:
QUERY # 2:
OUTPUT:
QUERY # 3:
Goto Create → Query Design add Table PATIENT STATUS close the Dialogue box.
In column one select PATIENT STATUS*.
In second column open build function in the column of expression elements go to
Database HOSPITAL → Tables →PATIENT STATUS ,Open bracket Add
Medicine_Cost (by double clicking on it) + Doctor_Fees(by double clicking)close the
bracket then click on ok. Then erase Expr1 from the column and in its place write
Room_Charges.
OUTPUT:
QUERY # 4:
OUTPUT:
QUERY # 5:
OUTPUT:
QUERY # 6:
Goto Create → Query Design add Table PATIENT and close the dialogue box.
Select PATIENT STATUS* in column 1, and Disease In column 2 and in its critera write
[Enter Disease] and untick the box. To display records of patients having particular
disease.
OUTPUT:
QUERY # 7:
Goto Create → Query Design , Add Query3 close the dialogue box.
Select Patient_Id in column 1, Doctor_Id in column 2, Disease in column 3,
Admit_Datein column 4, Medicine_cost in column 5, Doctor_Fees in column6,
Room_Charges in column 7 and in its criteria write: (select min (room_charges) from
Query3).
OUTPUT:
QUERY # 8:
Goto Create → Query Design add PATIENT STATUS Table close the Dialogue box.
In the tool bar click on Delete, then select Admit_Date in column one and in its criteria write
“1-Apr-23”.
OUTPUT:
QUERY # 9:
OUTPUT:
SQL QUERIES:
CREATE QUERY:
Create table PATEINT
(
Patient_ID TEXT Primary key,
Patient_Name TEXT,
Gender TEXT,
Age Number
);
INSERT QUERY:
Insert into table PATIENT
Values (“P1”, “Saqib Khan” , “Male” , “40”);
Query # 1:
Select Patient_status.Patient_ID, Pateint_status.Disease, Doctor_Profile.Doctor_Name
From Doctor_Profile inner join Patient_status
ON Doctor_Profile.Doctor_ID = Patient_Status.Doctor_ID
WHERE Patient_Status.Patient_ID = “P2”;
QUERY # 2:
Select patient.patient_ID,Patient.Patient_Name,patient.Gender,Patient_status.disease,
patient_status.Admit_Date
FROM Patient inner join Patient_status
ON patient.Patient_ID=Patient_status.patient_ID
WHERE patient.Gender=”FEMALE”;
QUERY # 3:
SELECT PATIENT STATUS.*,(Medicine_Cost+Doctor_Fees) AS Room_Charges
FROM PATIENT STATUS;
QUERY # 4:
SELECT PATIENT.Patient_Name, PATIENT.Patient_ID, DOCTOR_PROFILE.Doctor_Name
FROM (DOCTOR_PROFILE INNER JOIN PATIENT_STATUS ON DOCTOR_PROFILE.Doctor_ID =
PATIENT_STATUS.Doctor_ID) INNER JOIN PATIENT ON PATIENT_STATUS.Pateint_ID =
PATIENT.Patient_ID
QUERY # 5:
SELECT Max(salary) AS Second_Highest_salary
FROM Doctor_Profile
WHERE Salary<(Select max (salary) from Doctor_Profile);
QUERY # 6:
SELECT PATIENT_STATUS.*
FROM PATIENT_STATUS
WHERE Disease=[Enter Disease];
QUERY # 7:
SELECT Query3.Pateint_ID, Query3.Doctor_ID, Query3.Disease, Query3.Admit_Date,
Query3.Medicine_Cost, Query3.Doctor_Fees, Query3.Room_Charges, *
FROM Query3
WHERE Query3.Room_Charges=(select min(Room_Charges) from Query3);
QUERY # 8:
DELETE*
FROM PATIENT_STAUS
WHERE Admit_Date = “1-Apr-23”;
QUERY # 9:
UPDATE PATIENT_STATUS
SET Patient_ID = “P4”
WHERE Patient_ID = “P5”