Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Pinpoint your needs for improvement in interpersonal relations.

Answered: 1 week ago