Hospital Management SQL Answers
Hospital Management SQL Answers
Answers
Section A: Database Schema and Sample Data
1. 1. **Patients Table**
2. 2. **Doctors Table**
3. 3. **Appointments Table**
4. 4. **Treatments Table**
5. 5. **Medications Table**
6. 1. **Patients Table**
7. 2. **Doctors Table**
INSERT INTO Doctors (DoctorID, FirstName, LastName, Specialty, PhoneNumber, Email)
VALUES
(1, 'Alice', 'Johnson', 'Cardiology', '1231231234', '[email protected]'),
(2, 'Robert', 'Miller', 'Neurology', '9879879876', '[email protected]'),
(3, 'Linda', 'Taylor', 'Pediatrics', '6546546543', '[email protected]');
8. 3. **Appointments Table**
9. 4. **Treatments Table**
14. 4. Find the details of a specific patient using their PatientID (example PatientID: 1).
17. 7. Select all patients assigned to a specific doctor (example DoctorID: 2).
18. 8. Retrieve the names of patients who have appointments in the next week.
19. 9. List all treatments administered to a specific patient (example PatientID: 1).
20. 10. Count how many patients have been treated in the last month.
21. 11. Find the doctor with the highest number of appointments.
22. 12. Select all patients who were admitted in a specific month (example month: October
2024).
25. 15. List all doctors who specialize in a specific field (example field: Cardiology).
26. 16. Select patients whose names start with the letter 'J'.
27. 17. Find all medications prescribed to a specific patient (example PatientID: 2).
29. 19. Select all patients who have received a specific treatment (example TreatmentID: 1).
30. 20. Count how many patients are currently admitted to the hospital.
32. 2. Select the most frequently prescribed medication and the number of prescriptions.
33. 3. Retrieve a list of all patients and their corresponding doctors using a JOIN operation.
34. 4. Find all doctors who have treated more than 10 patients.
35. 5. List the titles of treatments that have been administered to multiple patients.
SELECT * FROM Patients WHERE PatientID NOT IN (SELECT PatientID FROM Appointments);
37. 2. Create a SQL statement to update the contact information of a specific patient and
display the updated information (example PatientID: 1).
UPDATE Patients SET PhoneNumber = '9998887776', Address = '321 Maple Lane' WHERE
PatientID = 1;
SELECT * FROM Patients WHERE PatientID = 1;