SQL Project — Working on Hospital Database

physician:

  • employeeid — this is a unique ID of a physician
  • name — this is the name of a physician
  • position — this is the designation of a physician
  • ssn — this is a security number of a physician

department:

  • departmentid — this is a unique ID for a department
  • name — this is the name of a department
  • head — this is the ID of the physician who is the head of a department, referencing to the column employeeid of the table physician

affiliated_with:

  • physician — this is the ID of the physicians which is referencing to the column employeeid of the physician table
  • department — this is the ID the department which is referencing to the column departmentid of the department table
  • primaryaffiliation — this is a logical column which indicate that whether the physicians are yet to be affiliated or not
  • Note: The combination of physician, department will come once in that table.

procedure:

  • code — this is the unique ID of a medical procedure
  • name — the name of the medical procedure
  • cost — the cost for the procedure

trained_in:

  • physician — this is ID of the physicians which is referencing to the column employeeid of the physician table
  • treatment — this is the ID of the medical procedure which is referencing to the column code of the procedure table
  • certificationdate — this is the starting date of certification
  • certificationexpires — this is the expiry date of certification
  • Note: The combination of physician and treatement will come once in that table.

patient:

  • ssn — this is a unique ID for each patient
  • name — this is the name of the patient
  • address — this is the address of the patient
  • phone — this is the phone number of the patient
  • insuranceid — this is the insurance id of the patient
  • pcp — this is the ID of the physician who primarily checked up the patient which is referencing to the column employeeid of the physician table

nurse:

  • employeeid — this is the unique ID for a nurse
  • name — name of the nurses
  • position — the designation of the nurses
  • registered — this is a logical column which indicate that whether the nurses are registered for nursing or not
  • ssn — this is the security number of a nurse

appointment:

  • appointmentid — this is the unique ID for an appointment
  • patient — this is the ID of each patient which is referencing to the ssn column of patient table
  • prepnurse — the ID of the nurse who may attend the patient with the physician, which is referencing to the column employeeid of the nurse table
  • physician — this is the ID the physicians which is referencing to the employeeid column of the physician table
  • start_dt_time — this is the schedule date and approximate time to meet the physician
  • end_dt_time — this is the schedule date and approximate time to end the meeting
  • examinationroom — this the room where to meet a patient to the physician

medication:

  • code — this is the unique ID for a medicine
  • name — this is the name of the medicine
  • brand — this is the brand of the medicine
  • description — this is the description of the medicine

prescribes:

  • physician — this is the ID of the physician referencing to the employeeid column of the physician table
  • patient — this is the ID of the patient which is referencing to the ssn column of the patient table
  • medication — the ID of the medicine which is referencing to the code of the medication table
  • date — the date and time of the prescribed medication
  • appointment — the prescription made by the physician to a patient who may taken an appointment which is referencing to column appointmentid of appointment table
  • dose — the dose prescribed by the physician
  • Note: The combination of physician, patient, medication, date will come once in that table.

block:

  • blockfloor — ID of the floor
  • blockcode — ID of the block
  • Note: The combination of blockfloor, blockcode will come once in that table.

room:

  • roomnumber — this is the unique ID of a room
  • roomtype — this is type of room
  • blockfloor — this is the floor ID where the room in
  • blockcode — this is the ID of the block where the room in
  • unavailable — this is the logical column which indicate that whether the room is available or not
  • Note: The blockfloor and blockcode columns are referring to the combination of blockfloor and blockcode columns of the table block.

on_call:

  • nurse — this is ID of the nurse which is referencing to the employeeid column of the table nurse
  • blockfloor — this is the ID of the floor
  • blockcode — this is the ID of block
  • oncallstart — the starting date and time of on call duration
  • oncallend — the ending date and time of on call duration
  • Note: The combination of nurse, blockfloor, blockcode, oncallstart, oncallend will come once in that table and the combination of blockfloor, blockcode columns are referring to the combination of blockfloor and blockcode columns of the table block .

stay:

  • stayid — this is unique ID for the admission
  • patient — this is the ID of the patient which is referencing the ssn column of patient table
  • room — this is the ID of the room where the patient admitted and which is referencing to the roomnumber column of the room table
  • start_time — this is the time when a patient admitted
  • end_time — this is the time how long a patient is staying

undergoes:

  • patient — this is ID of the patient which is referencing to the ssn column of the patient table
  • procedure — this is ID of the procedure and referencing to the code column of the procedure table
  • stay — this is the ID admission of a patient, which is referencing to the stayid column of the stay table
  • date — this is the date when a patient undergoes for a medical procedure
  • physician — this is the ID of a physician which is referencing to the column employeeid of the table physician
  • assistingnurse — this is the ID of a nurse who will assists the physician, referencing to the column employeeid of the table nurse
  • Note: The combination of patient, procedure, stay, date will come once in that table.

1. From the nurse table, find those nurses who are yet to be registered. Return all the fields of nurse table.

2. From the nurse table, find the nurse who is the head of their department. Return Nurse Name as “name”, Position as “Position”.

3. From the department and physician tables, find those physicians who are the head of the department. Return Department name as “Department” and Physician name as “Physician”.

4. From the appointment table, count the number of patients who booked an appointment with at least one Physician. Return count as “Number of patients taken at least one appointment”.

5. From the room table, find the floor and block where the room number 212 belongs. Return block floor as “Floor” and block code as “Block”.

6. From the room table, count the number available rooms. Return count as “Number of available rooms”.

7. From the room table, count the number of unavailable rooms. Return count as “Number of unavailable rooms”.

8. From the physician, affiliated_with, and department tables, find the physician and the departments they are affiliated with. Return Physician name as “Physician”, and department name as “Department”.

9. From the physician, trained_in, and procedure tables, find those physicians who have trained for special treatment. Return Physician name as “Physician”, treatment procedure name as “Treatment”.

10. From the physician, affiliated_with, and department tables, find those physicians who are yet to be affiliated. Return Physician name as “Physician”, Position, and department as “Department”.

11. From the physician and trained_in tables, find those physicians who are not a specialized physician. Return Physician name as “Physician”, position as “Designation”.

12. From the patient and physician tables, find the patients with their physicians by whom they got their preliminary treatment. Return Patient name as “Patient”, address as “Address” and Physician name as “Physician”.

13. From the patient and appointment tables, find the patients and the number of physicians they have taken appointment. Return Patient name as “Patient”, number of Physicians as “Appointment for No. of Physicians”.

14. From the appointment table, count number of unique patients who got an appointment for examination room ‘C’. Return unique patients as “No. of patients got appointment for room C”.

15. From the patient and appointment tables, find the name of the patients and the number of the room where they have to go for their treatment. Return patient name as “Patient”, examination room as “Room No.”, and starting date time as Date “Date and Time of appointment”.

16. From the nurse and appointment tables, find the name of the nurses and the room scheduled, where they will assist the physicians. Return Nurse Name as “Name of the Nurse” and examination room as “Room No.”.

17. From the patient, appointment, nurse, and physician tables, find those patients who taken the appointment on the 25th of April at 10 am. Return Name of the patient, Name of the Nurse assisting the physician, Physician Name as “Name of the physician”, examination room as “Room No.”, schedule date and approximate time to meet the physician.

18. From the patient, appointment, and physician tables, find those patients and their physicians who do not require any assistance of a nurse. Return Name of the patient as “Name of the patient”, Name of the Physician as “Name of the physician” and examination room as “Room No.”.

19. From the patient, prescribes, physician, and medication tables, find the patients and their treating physicians and medication. Return Patient name as “Patient”, Physician name as “Physician”, Medication name as “Medication”.

20. From the patient, presrcribes, physician, and medication tables, find those patients who have taken an advanced appointment. Return Patient name as “Patient”, Physician name as “Physician” and Medication name as “Medication”.

21. From the patient, presrcribes, physician, and medication tables, find those patients who did not take any appointment. Return Patient name as “Patient”, Physician name as “Physician” and Medication name as “Medication”.

22. From the room table, count the number of available rooms in each block. Sort the result-set on ID of the block. Return ID of the block as “Block”, count number of available rooms as “Number of available rooms”.

23. From the room table, count the number of available rooms in each floor. Sort the result-set on block floor. Return floor ID as “Floor” and count the number of available rooms as “Number of available rooms”.

24. From the room table, count the number of available rooms for each floor in each block. Sort the result-set on floor ID, ID of the block. Return the floor ID as “Floor”, ID of the block as “Block”, and number of available rooms as “Number of available rooms”.

25. From the room table, count the number of unavailable rooms for each block in each floor. Sort the result-set on block floor, block code. Return the floor ID as “Floor”, block ID as “Block”, and number of unavailable as “Number of unavailable rooms”.

26. From the room table, find the floor where the maximum numbers of rooms are available. Return floor ID as “Floor”, count “Number of available rooms”.

27. From the room table, find the floor where the minimum numbers of rooms are available. Return floor ID as “Floor”, Number of available rooms.

28. From the patient, stay, and room tables, find the name of the patients, their block, floor, and room number where they admitted.

29. From the nurse and on_call tables, find the nurses and the block where they are booked for attending the patients on call. Return Nurse Name as “Nurse”, Block code as “Block”.

30. From the patient, undergoes, physician, nurse, stay, and room tables, get
a) name of the patient,
b) name of the physician who is treating him or her,
c) name of the nurse who is attending him or her,
d) the date of release,
e) in which room the patient has admitted and which floor and block the room belongs to respectively.

31. From the patient, undergoes, trained_in, procedure, and patient tables, find all the physicians, their procedure, date when the procedure was carried out and name of the patient on which procedure have been carried out but those physicians are not certified for that procedure. Return Physician Name as “Physician”, Procedure Name as “Procedure”, date, and Patient. Name as “Patient”.

32. From the physician, undergoes, trained_in, procedure, and patient tables, find all those physicians who completed a medical procedure with certification after the date of expiration of their certificate. Return Physician Name as “Physician”, Position as “Position”, Procedure Name as “Procedure”, Date of Procedure as “Date of Procedure”, expiry date of certification as “Expiry Date of Certificate”, and Patient Name as “Patient”.

33. From the nurse, on_call, and room tables, find those nurses who have ever been on call for room 122. Return name of the nurses.

34. From the patient, prescribes, and physician tables, find those patients who have been prescribed by some medication by his/her physician who has carried out primary care. Return Patient name as “Patient”, and Physician Name as “Physician”.

35. From the patient, physician, undergoes, and procedure tables, find those patients who have been undergone a procedure costing more than $5,000 and the name of that physician who has carried out primary care. Return name of the patient as “Patient”, name of the physician as “Primary Physician”, and cost for the procedure as “Procedure Cost”.

36. From the patient, physician, appointment, and nurse tables, find those patients who had at least two appointments where the nurse who prepped the appointment was a registered nurse and the physician who has carried out primary care. Return Patient name as “Patient”, Physician name as “Primary Physician”, and Nurse Name as “Nurse”.

37. From the patient, physician, and department tables, find those patients whose primary care a physician who is not the head of any department takes. Return Patient name as “Patient”, Physician Name as “Primary Physician”.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store