Question: Write SQL queries to perform the following operations. In each case show the SQL statement you used and the output from MySQL. The tables of
Write SQL queries to perform the following operations. In each case show the SQL statement you used and the output from MySQL.
The tables of Hospital database are as follows:
team (team_code, telephone_no, staff_no)
consists_of (staff_no, team_code)
doctor (staff_no, doctor_name, position)
specialist (staff_no, specialism)
patient (patient_id, patient_name, gender, height, weight, staff_no, ward_no)
ward (ward_no, ward_name, number_of_beds)
nurse (staff_no, nurse_name, ward_no)
supervises (staff_no, supervisor)
treatment (staff_no, patient_id, start_date, reason)
prescription (prescription_no, quantity, daily_dosage, staff_no, patient_id, start_date, drug_code)
small_occupied_by(patirnt_id, ward_no)
drug (drug_code, drug_name, type, price)
a) List prescription numbers and drugs whose codes are either P51 or X01 in these prescriptions.
b) Find the team codes along with staff numbers in each team.
c) Retrieve the staff numbers, patient identifiers and names along with starting date of all treatments that were between 2007-01-01 and 2007-02-01.
d) List the ward numbers and names along with patient identifiers and the number of patients in each ward. The output table should be sorted based on ward numbers in an ascending way.
e) Find drug codes and names for all drugs that were not given in any prescription.
f) Give the output table that has the staff numbers and names of all doctors who are not specialist and gave treatments to the patients.
g) Find the patient identifier and the average of drug prices for each patient that his drug price is greater than the average of drug prices of the same drug type.
h) Give the drug code along with the sum of quantities for each drug that its sum of quantities is greater than 100.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
