Database: hospital_1

Question: Find the department with the most employees.
SQL: SELECT name FROM department GROUP BY departmentID ORDER BY count(departmentID) DESC LIMIT 1;

Question: Tell me the employee id of the head of the department with the least employees.
SQL: SELECT head FROM department GROUP BY departmentID ORDER BY count(departmentID) LIMIT 1;

Question: Find the name and position of the head of the department with the least employees.
SQL: SELECT T2.name ,  T2.position FROM department AS T1 JOIN physician AS T2 ON T1.head  =  T2.EmployeeID GROUP BY departmentID ORDER BY count(departmentID) LIMIT 1;

Question: List the names of patients who have made appointments.
SQL: SELECT name FROM appointment AS T1 JOIN patient AS T2 ON T1.patient  =  T2.ssn

Question: Which patients made more than one appointment? Tell me the name and phone number of these patients.
SQL: SELECT name ,  phone FROM appointment AS T1 JOIN patient AS T2 ON T1.patient  =  T2.ssn GROUP BY T1.patient HAVING count(*)  >  1

Question: What is the id of the appointment that started most recently?
SQL: SELECT appointmentid FROM appointment ORDER BY START DESC LIMIT 1

Question: What are the names of all the physicians who took appointments.
SQL: SELECT T2.name FROM appointment AS T1 JOIN physician AS T2 ON T1.Physician  =  T2.EmployeeID

Question: Which physicians have never taken any appointment? Find their names.
SQL: SELECT name FROM physician EXCEPT SELECT T2.name FROM appointment AS T1 JOIN physician AS T2 ON T1.Physician  =  T2.EmployeeID

Question: What are the name and primarily affiliated department name of each physician?
SQL: SELECT T1.name ,  T3.name FROM physician AS T1 JOIN affiliated_with AS T2 ON T1.EmployeeID  =  T2.physician JOIN department AS T3 ON T2.department  =  T3.DepartmentID WHERE T2.PrimaryAffiliation  =  1

Question: Find the name of the patient who made the appointment with the most recent start date.
SQL: SELECT T1.name FROM patient AS T1 JOIN appointment AS T2 WHERE T1.ssn = T2.patient ORDER BY T2.start DESC LIMIT 1

Question: Count the number of patients who stayed in room 112.
SQL: SELECT count(patient) FROM stay WHERE room  =  112

Question: Find the number of patients' prescriptions physician John Dorian made.
SQL: SELECT count(T1.SSN) FROM patient AS T1 JOIN prescribes AS T2 ON T1.SSN  =  T2.patient JOIN physician AS T3 ON T2.physician  =  T3.employeeid WHERE T3.name = "John Dorian"

Question: What is the name of the medication used for the patient staying in room 111?
SQL: SELECT T4.name FROM stay AS T1 JOIN patient AS T2 ON T1.Patient  =  T2.SSN JOIN Prescribes AS T3 ON T3.Patient  =  T2.SSN JOIN Medication AS T4 ON T3.Medication  =  T4.Code WHERE room  =  111

Question: What is the id of the patient who stayed in room 111 most recently?
SQL: SELECT patient FROM stay WHERE room  =  111 ORDER BY staystart DESC LIMIT 1

Question: Find the name of the nurse who has the largest number of appointments.
SQL: SELECT T1.name FROM nurse AS T1 JOIN appointment AS T2 ON T1.employeeid  =  T2.prepnurse GROUP BY T1.employeeid ORDER BY count(*) DESC LIMIT 1