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 unique block codes that have available rooms? [/INST]

Output: SELECT DISTINCT blockcode FROM room WHERE unavailable  =  0;


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 distinct block codes where some rooms are available. [/INST]

Output: SELECT DISTINCT blockcode FROM room WHERE unavailable  =  0;


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 different types of rooms are there? [/INST]

Output: SELECT count(DISTINCT roomtype) FROM room;


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 distinct room types available. [/INST]

Output: SELECT count(DISTINCT roomtype) FROM room;


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 names of the physicians who prescribe medication Thesisin? [/INST]

Output: SELECT DISTINCT T1.name FROM physician AS T1 JOIN prescribes AS T2 ON T1.employeeid = T2.physician JOIN medication AS T3 ON T3.code = T2.medication WHERE T3.name  =  "Thesisin";


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 all the physicians who prescribe Thesisin as medication. [/INST]

Output: SELECT DISTINCT T1.name FROM physician AS T1 JOIN prescribes AS T2 ON T1.employeeid = T2.physician JOIN medication AS T3 ON T3.code = T2.medication WHERE T3.name  =  "Thesisin";


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 physicians who prescribe some medication whose brand is X? [/INST]

Output: SELECT DISTINCT T1.name ,  T1.position FROM physician AS T1 JOIN prescribes AS T2 ON T1.employeeid = T2.physician JOIN medication AS T3 ON T3.code = T2.medication WHERE T3.Brand  =  "X";


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 prescribe a medication of brand X? Tell me the name and position of those physicians. [/INST]

Output: SELECT DISTINCT T1.name ,  T1.position FROM physician AS T1 JOIN prescribes AS T2 ON T1.employeeid = T2.physician JOIN medication AS T3 ON T3.code = T2.medication WHERE T3.Brand  =  "X";


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 medications prescribed for each brand. [/INST]

Output: SELECT count(*) ,  T1.name FROM medication AS T1 JOIN prescribes AS T2 ON T1.code = T2.medication GROUP BY T1.brand;


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 medications are prescribed for each brand? [/INST]

Output: SELECT count(*) ,  T1.name FROM medication AS T1 JOIN prescribes AS T2 ON T1.code = T2.medication GROUP BY T1.brand;


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 whose position title contains the word 'senior'. [/INST]

Output: SELECT name FROM physician WHERE POSITION LIKE '%senior%';


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 the physicians who have 'senior' in their titles. [/INST]

Output: SELECT name FROM physician WHERE POSITION LIKE '%senior%';


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 has the most recent undergoing treatment? [/INST]

Output: SELECT patient FROM undergoes ORDER BY dateundergoes 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: Which patient is undergoing the most recent treatment? [/INST]

Output: SELECT patient FROM undergoes ORDER BY dateundergoes 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 names of all patients who have an undergoing treatment and are staying in room 111. [/INST]

Output: SELECT DISTINCT T2.name FROM undergoes AS T1 JOIN patient AS T2 ON T1.patient = T2.SSN JOIN stay AS T3 ON T1.Stay  =  T3.StayID WHERE T3.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 are the names of patients who are staying in room 111 and have an undergoing treatment? [/INST]

Output: SELECT DISTINCT T2.name FROM undergoes AS T1 JOIN patient AS T2 ON T1.patient = T2.SSN JOIN stay AS T3 ON T1.Stay  =  T3.StayID WHERE T3.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: List the names of all distinct nurses ordered by alphabetical order? [/INST]

Output: SELECT DISTINCT name FROM nurse ORDER BY name;


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 alphabetically ordered list of all the distinct names of nurses? [/INST]

Output: SELECT DISTINCT name FROM nurse ORDER BY name;


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 nurses who are nursing an undergoing treatment. [/INST]

Output: SELECT DISTINCT T2.name FROM undergoes AS T1 JOIN nurse AS T2 ON T1.AssistingNurse  =  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 nurses are in charge of patients undergoing treatments? [/INST]

Output: SELECT DISTINCT T2.name FROM undergoes AS T1 JOIN nurse AS T2 ON T1.AssistingNurse  =  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 names of all distinct medications, ordered in an alphabetical order. [/INST]

Output: SELECT DISTINCT name FROM medication ORDER BY name;


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 alphabetically ordered list of all distinct medications? [/INST]

Output: SELECT DISTINCT name FROM medication ORDER BY name;


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 the physician who prescribed the highest dose? [/INST]

Output: SELECT T1.name FROM physician AS T1 JOIN prescribes AS T2 ON T1.employeeid = T2.physician ORDER BY T2.dose 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 physician who prescribed the highest dose. What is his or her name? [/INST]

Output: SELECT T1.name FROM physician AS T1 JOIN prescribes AS T2 ON T1.employeeid = T2.physician ORDER BY T2.dose 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 physicians' employee ids together with their primary affiliation departments' ids. [/INST]

Output: SELECT physician ,  department FROM affiliated_with WHERE 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 each physician's employee id and department id primarily affiliated. [/INST]

Output: SELECT physician ,  department FROM affiliated_with WHERE 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: List the names of departments where some physicians are primarily affiliated with. [/INST]

Output: SELECT DISTINCT T2.name FROM affiliated_with AS T1 JOIN department AS T2 ON T1.department = T2.departmentid WHERE 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 names of departments that have primarily affiliated physicians. [/INST]

Output: SELECT DISTINCT T2.name FROM affiliated_with AS T1 JOIN department AS T2 ON T1.department = T2.departmentid WHERE 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 nurses are on call with block floor 1 and block code 1? Tell me their names. [/INST]

Output: SELECT nurse FROM on_call WHERE blockfloor  =  1 AND blockcode  =  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 ids of the nurses who are on call in block floor 1 and block code 1. [/INST]

Output: SELECT nurse FROM on_call WHERE blockfloor  =  1 AND blockcode  =  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 highest cost, lowest cost and average cost of procedures? [/INST]

Output: SELECT MAX(cost) ,  MIN(cost) ,  AVG(cost) FROM procedures;


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 highest, lowest, and average cost of procedures. [/INST]

Output: SELECT MAX(cost) ,  MIN(cost) ,  AVG(cost) FROM procedures;


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 and cost of all procedures sorted by the cost from the highest to the lowest. [/INST]

Output: SELECT name ,  cost FROM procedures ORDER BY cost DESC;


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: Sort the list of names and costs of all procedures in the descending order of cost. [/INST]

Output: SELECT name ,  cost FROM procedures ORDER BY cost DESC;


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 three most expensive procedures. [/INST]

Output: SELECT name FROM procedures ORDER BY cost LIMIT 3;