Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Tell me the employee id of the head of the department with the least employees. [/INST]

Output: SELECT head FROM department GROUP BY departmentID ORDER BY count(departmentID) LIMIT 1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: what is the name and position of the head whose department has least number of employees? [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the name and position of the head of the department with the least employees. [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: What are names of patients who made an appointment? [/INST]

Output: SELECT name FROM appointment AS T1 JOIN patient AS T2 ON T1.patient  =  T2.ssn;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: List the names of patients who have made appointments. [/INST]

Output: SELECT name FROM appointment AS T1 JOIN patient AS T2 ON T1.patient  =  T2.ssn;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: what are name and phone number of patients who had more than one appointment? [/INST]

Output: SELECT name ,  phone FROM appointment AS T1 JOIN patient AS T2 ON T1.patient  =  T2.ssn GROUP BY T1.patient HAVING count(*)  >  1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Which patients made more than one appointment? Tell me the name and phone number of these patients. [/INST]

Output: SELECT name ,  phone FROM appointment AS T1 JOIN patient AS T2 ON T1.patient  =  T2.ssn GROUP BY T1.patient HAVING count(*)  >  1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the id of the appointment with the most recent start date? [/INST]

Output: SELECT appointmentid FROM appointment ORDER BY START DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: What is the id of the appointment that started most recently? [/INST]

Output: SELECT appointmentid FROM appointment ORDER BY START DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: List the name of physicians who took some appointment. [/INST]

Output: SELECT T2.name FROM appointment AS T1 JOIN physician AS T2 ON T1.Physician  =  T2.EmployeeID;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: What are the names of all the physicians who took appointments. [/INST]

Output: SELECT T2.name FROM appointment AS T1 JOIN physician AS T2 ON T1.Physician  =  T2.EmployeeID;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: List the name of physicians who never took any appointment. [/INST]

Output: SELECT name FROM physician EXCEPT SELECT T2.name FROM appointment AS T1 JOIN physician AS T2 ON T1.Physician  =  T2.EmployeeID;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Which physicians have never taken any appointment? Find their names. [/INST]

Output: SELECT name FROM physician EXCEPT SELECT T2.name FROM appointment AS T1 JOIN physician AS T2 ON T1.Physician  =  T2.EmployeeID;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the names of all physicians and their primary affiliated departments' names. [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: What are the name and primarily affiliated department name of each physician? [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: What is the name of the patient who made the most recent appointment? [/INST]

Output: SELECT T1.name FROM patient AS T1 JOIN appointment AS T2 ON T1.ssn = T2.patient ORDER BY T2.start DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the name of the patient who made the appointment with the most recent start date. [/INST]

Output: SELECT T1.name FROM patient AS T1 JOIN appointment AS T2 ON T1.ssn = T2.patient ORDER BY T2.start DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: How many patients stay in room 112? [/INST]

Output: SELECT count(patient) FROM stay WHERE room  =  112;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Count the number of patients who stayed in room 112. [/INST]

Output: SELECT count(patient) FROM stay WHERE room  =  112;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: How many patients' prescriptions are made by physician John Dorian? [/INST]

Output: 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";


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the number of patients' prescriptions physician John Dorian made. [/INST]

Output: 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";


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the name of medication used on the patient who stays in room 111? [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: What is the name of the medication used for the patient staying in room 111? [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the patient who most recently stayed in room 111. [/INST]

Output: SELECT patient FROM stay WHERE room  =  111 ORDER BY staystart DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: What is the id of the patient who stayed in room 111 most recently? [/INST]

Output: SELECT patient FROM stay WHERE room  =  111 ORDER BY staystart DESC LIMIT 1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: What is the name of the nurse has the most appointments? [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the name of the nurse who has the largest number of appointments. [/INST]

Output: 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;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: How many patients do each physician take care of? List their names and number of patients they take care of. [/INST]

Output: SELECT T1.name ,  count(*) FROM physician AS T1 JOIN patient AS T2 ON T1.employeeid  =  T2.PCP GROUP BY T1.employeeid;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Return the name of each physician and the number of patients he or she treats. [/INST]

Output: SELECT T1.name ,  count(*) FROM physician AS T1 JOIN patient AS T2 ON T1.employeeid  =  T2.PCP GROUP BY T1.employeeid;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the name of physicians who are in charge of more than one patient. [/INST]

Output: SELECT T1.name FROM physician AS T1 JOIN patient AS T2 ON T1.employeeid  =  T2.PCP GROUP BY T1.employeeid HAVING count(*)  >  1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Which physicians are in charge of more than one patient? Give me their names. [/INST]

Output: SELECT T1.name FROM physician AS T1 JOIN patient AS T2 ON T1.employeeid  =  T2.PCP GROUP BY T1.employeeid HAVING count(*)  >  1;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the number of rooms located on each block floor. [/INST]

Output: SELECT count(*) ,  T1.blockfloor FROM BLOCK AS T1 JOIN room AS T2 ON T1.blockfloor  =  T2.blockfloor AND T1.blockcode  =  T2.blockcode GROUP BY T1.blockfloor;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: How many rooms does each block floor have? [/INST]

Output: SELECT count(*) ,  T1.blockfloor FROM BLOCK AS T1 JOIN room AS T2 ON T1.blockfloor  =  T2.blockfloor AND T1.blockcode  =  T2.blockcode GROUP BY T1.blockfloor;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: Find the number of rooms for different block code? [/INST]

Output: SELECT count(*) ,  T1.blockcode FROM BLOCK AS T1 JOIN room AS T2 ON T1.blockfloor  =  T2.blockfloor AND T1.blockcode  =  T2.blockcode GROUP BY T1.blockcode;


Input:
[INST] Here is a database schema:
Physician :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
SSN [ INT ]

Department :
DepartmentID [ INT ] primary_key
Name [ TEXT ]
Head [ INT ] Department.Head = Physician.EmployeeID

Affiliated_With :
Physician [ INT ] primary_key Affiliated_With.Physician = Physician.EmployeeID
Department [ INT ] Affiliated_With.Department = Department.DepartmentID
PrimaryAffiliation [ TEXT ]

Procedures :
Code [ INT ] primary_key
Name [ TEXT ]
Cost [ INT ]

Trained_In :
Physician [ INT ] primary_key Trained_In.Physician = Physician.EmployeeID
Treatment [ INT ] Trained_In.Treatment = Procedures.Code
CertificationDate [ TEXT ]
CertificationExpires [ TEXT ]

Patient :
SSN [ INT ] primary_key
Name [ TEXT ]
Address [ TEXT ]
Phone [ TEXT ]
InsuranceID [ INT ]
PCP [ INT ] Patient.PCP = Physician.EmployeeID

Nurse :
EmployeeID [ INT ] primary_key
Name [ TEXT ]
Position [ TEXT ]
Registered [ TEXT ]
SSN [ INT ]

Appointment :
AppointmentID [ INT ] primary_key
Patient [ INT ] Appointment.Patient = Patient.SSN
PrepNurse [ INT ] Appointment.PrepNurse = Nurse.EmployeeID
Physician [ INT ] Appointment.Physician = Physician.EmployeeID
Start [ TEXT ]
End [ TEXT ]
ExaminationRoom [ TEXT ]

Medication :
Code [ INT ] primary_key
Name [ TEXT ]
Brand [ TEXT ]
Description [ TEXT ]

Prescribes :
Physician [ INT ] primary_key Prescribes.Physician = Physician.EmployeeID
Patient [ INT ] Prescribes.Patient = Patient.SSN
Medication [ INT ] Prescribes.Medication = Medication.Code
Date [ TEXT ]
Appointment [ INT ] Prescribes.Appointment = Appointment.AppointmentID
Dose [ TEXT ]

Block :
BlockFloor [ INT ] primary_key
BlockCode [ INT ]

Room :
RoomNumber [ INT ] primary_key
RoomType [ TEXT ]
BlockFloor [ INT ] Room.BlockFloor = Block.BlockFloor
BlockCode [ INT ] Room.BlockCode = Block.BlockCode
Unavailable [ TEXT ]

On_Call :
Nurse [ INT ] primary_key On_Call.Nurse = Nurse.EmployeeID
BlockFloor [ INT ] On_Call.BlockFloor = Block.BlockFloor
BlockCode [ INT ] On_Call.BlockCode = Block.BlockCode
OnCallStart [ TEXT ]
OnCallEnd [ TEXT ]

Stay :
StayID [ INT ] primary_key
Patient [ INT ] Stay.Patient = Patient.SSN
Room [ INT ] Stay.Room = Room.RoomNumber
StayStart [ TEXT ]
StayEnd [ TEXT ]

Undergoes :
Patient [ INT ] primary_key Undergoes.Patient = Patient.SSN
Procedures [ INT ] Undergoes.Procedures = Procedures.Code
Stay [ INT ] Undergoes.Stay = Stay.StayID
DateUndergoes [ TEXT ]
Physician [ INT ] Undergoes.Physician = Physician.EmployeeID
AssistingNurse [ INT ] Undergoes.AssistingNurse = Nurse.EmployeeID

Please write me a SQL statement that answers the following question: How many rooms are located for each block code? [/INST]

Output: SELECT count(*) ,  T1.blockcode FROM BLOCK AS T1 JOIN room AS T2 ON T1.blockfloor  =  T2.blockfloor AND T1.blockcode  =  T2.blockcode GROUP BY T1.blockcode;