Esercitazione sql con Db Hospital

Esercitazione sql con Db Hospital

(online db and sql editor)

Dato lo schema relazione come da immagine iniziare a consultare le tabelle implicate:

List of tables in the hospital database:

physician:

department:

affiliated_with:

procedure:

trained_in:

patient:

nurse:

appointment:

medication:

prescribes:

block:

room:

on_call:

stay:

undergoes:

The database for hospital management system used for this exercises is based upon a database available in wikipedia. Sturcture and Data are may have gone through alterations sporadically.

Ecco le query necessarie per iniziare ad interrogare il DB:

1 query:   Table nurse:
Results:

employeeid | name | position | registered | ssn
101 | Carla Espinosa | Head Nurse | t | 111111110
102 | Laverne Roberts | Nurse | t | 222222220
103 | Paul Flowers | Nurse | f | 333333330

go to editor to try to code the right query:

2) Write a query in SQL to find the name of the nurse who are the head of their department. 

Sample table: nurse

employeeid | name | position | registered | ssn ————+—————–+————+————+———– 101 | Carla Espinosa | Head Nurse | t | 111111110 102 | Laverne Roberts | Nurse | t | 222222220 103 | Paul Flowers | Nurse | f | 333333330

3Write a query in SQL to obtain the name of the physicians who are the head of each department. 

Sample table: physician

employeeid | name | position | ssn ————+——————-+——————————+———– 1 | John Dorian | Staff Internist | 111111111 2 | Elliot Reid | Attending Physician | 222222222 3 | Christopher Turk | Surgical Attending Physician | 333333333 4 | Percival Cox | Senior Attending Physician | 444444444 5 | Bob Kelso | Head Chief of Medicine | 555555555 6 | Todd Quinlan | Surgical Attending Physician | 666666666 7 | John Wen | Surgical Attending Physician | 777777777 8 | Keith Dudemeister | MD Resident | 888888888 9 | Molly Clock | Attending Psychiatrist | 999999999

Write a query in SQL to obtain the name of all those physicians who completed a medical procedure with certification after the date of expiration of their certificate, their position, procedure they have done, date of procedure, name of the patient on which the procedure had been applied and the date when the certification expired.

Sample table: physician

Sample table: undergoes

Sample table: patient

Sample table: procedure

Sample table: trained_in

35. Write a query in SQL to obtain the names of all the nurses who have ever been on call for room 122.   Go to the editor

Sample table: nurse

Sample table: on_call

Sample table: room

36. Write a query in SQL to Obtain the names of all patients who has been prescribed some medication by his/her physician who has carried out primary care and the name of that physician.

Sample table: patient

Sample table: prescribes

Sample table: physician

37. Write a query in SQL to obtain the names of all patients who has been undergone a procedure costing more than $5,000 and the name of that physician who has carried out primary care.   Go to the editor

Sample table: patient

Sample table: undergoes

Sample table: physician

Sample table: procedure

3 Write a query in SQL to Obtain the names of all patients who had at least two appointment where the nurse who prepped the appointment was a registered nurse and the physician who has carried out primary care.   Go to the editor

Sample table: appointment

Sample table: patient

Sample table: nurse

Sample table: physician

Write a query in SQL to Obtain the names of all patients whose primary care is taken by a physician who is not the head of any department and name of that physician along with their primary care physician.

Sample table: patient

Sample table: department

Sample table: physician

FREE