input
stringlengths 193
2.69k
| output
stringlengths 24
744
|
|---|---|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
observations :
DATE [ DATE ]
PATIENT [ TEXT ] observations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] observations.ENCOUNTER = encounters.ID
CODE [ TEXT ]
DESCRIPTION [ TEXT ]
VALUE [ REAL ]
UNITS [ TEXT ]
Please write me a SQL statement that answers the following question: What is the average body weight of Asian patients? [/INST]
|
SELECT SUM(T2.VALUE) / COUNT(T1.patient) FROM patients AS T1 INNER JOIN observations AS T2 ON T1.patient = T2.PATIENT WHERE T1.race = 'asian' AND T2.DESCRIPTION = 'Body Weight' AND T2.UNITS = 'kg';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
allergies :
START [ TEXT ]
STOP [ TEXT ]
PATIENT [ TEXT ] allergies.PATIENT = patients.patient
ENCOUNTER [ TEXT ] allergies.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Write down the Social Security numbers of patients who have latex allergies. [/INST]
|
SELECT T1.ssn FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Latex allergy';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
allergies :
START [ TEXT ]
STOP [ TEXT ]
PATIENT [ TEXT ] allergies.PATIENT = patients.patient
ENCOUNTER [ TEXT ] allergies.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How long did Isadora Moen's allergy last? Tell me what kind of allergy she has. [/INST]
|
SELECT CASE WHEN SUBSTR(T1.STOP, -2, 1) != '9' THEN SUBSTR(T1.STOP, LENGTH(T1.STOP) - 1) + 2000 END - CASE WHEN SUBSTR(T1.START, -2, 1) = '9' THEN SUBSTR(T1.START, LENGTH(T1.START) - 1) + 1900 ELSE SUBSTR(T1.START, LENGTH(T1.START) - 1) + 2000 END AS years , T1.DESCRIPTION FROM allergies AS T1 INNER JOIN patients AS T2 ON T2.patient = T1.PATIENT WHERE T1.STOP IS NOT NULL AND T1.START IS NOT NULL AND T2.first = 'Isadora' AND T2.last = 'Moen';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many times was Elly Koss given a care plan between 1/11/2009 and 10/23/2010? [/INST]
|
SELECT COUNT(T2.PATIENT) FROM patients AS T1 INNER JOIN careplans AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Elly' AND T1.last = 'Koss' AND T2.START BETWEEN '2009-01-11' AND '2010-10-23';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: In 2009, who among the married patients had undergone a care plan for more than 60 days? [/INST]
|
SELECT DISTINCT T1.first, T1.last FROM patients AS T1 INNER JOIN careplans AS T2 ON T1.patient = T2.PATIENT WHERE T1.marital = 'M' AND strftime('%J', T2.STOP) - strftime('%J', T2.START) > 60;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
immunizations :
DATE [ DATE ]
PATIENT [ TEXT ] immunizations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] immunizations.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Please provide the dates on which Elly Koss was immunized with the influenza seasonal injectable preservative-free vaccine. [/INST]
|
SELECT T2.DATE FROM patients AS T1 INNER JOIN immunizations AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Influenza seasonal injectable preservative free' AND T1.first = 'Elly' AND T1.last = 'Koss';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
immunizations :
DATE [ DATE ]
PATIENT [ TEXT ] immunizations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] immunizations.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: From 7/9/2010 to 10/29/2013, how many black patients were immunized with the meningococcal MCV4P vaccine? [/INST]
|
SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN immunizations AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'meningococcal MCV4P' AND T2.DATE BETWEEN '2010-07-09' AND '2013-10-29' AND T1.race = 'black';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
immunizations :
DATE [ DATE ]
PATIENT [ TEXT ] immunizations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] immunizations.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Give me the immunization codes and dates on which Ms. Jacquelyn Shanahan was immunized with influenza seasonal injectable preservative-free vaccine. [/INST]
|
SELECT DISTINCT T2.CODE, T2.DATE FROM patients AS T1 INNER JOIN immunizations AS T2 ON T1.patient = T2.PATIENT WHERE T1.prefix = 'Ms.' AND T1.first = 'Jacquelyn' AND T1.last = 'Shanahan' AND T2.DESCRIPTION = 'Influenza seasonal injectable preservative free';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How long did Berry Keebler take the Acetaminophen 160 MG when he was admitted due to acute bronchitis? [/INST]
|
SELECT strftime('%J', T2.STOP) - strftime('%J', T2.START) AS takenDays FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Berry' AND T1.last = 'Keebler' AND T2.REASONDESCRIPTION = 'Acute bronchitis (disorder)' AND T2.DESCRIPTION = 'Acetaminophen 160 MG';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: In 2010, how many single patients took Nitrofurantoin 5 mg/ML [Furadantin] to cure cystitis? [/INST]
|
SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T1.marital = 'S' AND T2.REASONDESCRIPTION = 'Cystitis' AND T2.DESCRIPTION = 'Nitrofurantoin 5 MG/ML [Furadantin]' AND strftime('%Y', T2.START) = '2010';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Tell me the reason for Lavelle Vandervort's encounter on 11/20/2013? [/INST]
|
SELECT T2.REASONDESCRIPTION FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT WHERE T2.DATE = '2013-11-20' AND T1.first = 'Lavelle' AND T1.last = 'Vandervort';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: From 1/9/2011 to 8/29/2012, how many German patients have their outpatient encounters? [/INST]
|
SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT WHERE T1.ethnicity = 'german' AND T2.DATE BETWEEN '2011-01-09' AND '2012-08-29' AND T2.DESCRIPTION = 'Outpatient Encounter';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: What is the social security number and address of the patient who encountered viral sinusitis symptoms on 6/13/2008? [/INST]
|
SELECT T1.ssn, T1.address FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT WHERE T2.DATE = '2008-06-13' AND T2.REASONDESCRIPTION = 'Viral sinusitis (disorder)' AND T2.DESCRIPTION = 'Encounter for symptom';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Give me the reason, name of the drug, and duration of medication under encounter ID 23c293ec-dbae-4a22-896e-f12cf3c8bac3. Tell me if the patient is still alive. [/INST]
|
SELECT T2.REASONDESCRIPTION, T2.DESCRIPTION , strftime('%J', T2.STOP) - strftime('%J', T2.START) AS days , CASE WHEN T1.deathdate IS NULL THEN 'alive' ELSE 'dead' END FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.ENCOUNTER = '23c293ec-dbae-4a22-896e-f12cf3c8bac3';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
allergies :
START [ TEXT ]
STOP [ TEXT ]
PATIENT [ TEXT ] allergies.PATIENT = patients.patient
ENCOUNTER [ TEXT ] allergies.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many patients with shellfish allergies died when they were under 12 years old? Please give their full names. [/INST]
|
SELECT T1.first, T1.last FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Shellfish allergy' AND CAST((strftime('%J', T1.deathdate) - strftime('%J', T1.birthdate)) AS REAL) / 365 < 12;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How long was Mr. Major D'Amore prescribed with Amoxicillin 250 MG / Clavulanate 125 MG [Augmentin]? [/INST]
|
SELECT strftime('%J', T2.STOP) - strftime('%J', T2.START) AS days FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = ' Amoxicillin 250 MG / Clavulanate 125 MG [Augmentin]' AND T1.first = 'Major' AND T1.last = 'D''Amore';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many types of medication have been prescribed to Mr. Major D'Amore since his visit to the hospital? [/INST]
|
SELECT COUNT(DISTINCT T2.DESCRIPTION) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Major' AND T1.last = 'D''Amore';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
observations :
DATE [ DATE ]
PATIENT [ TEXT ] observations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] observations.ENCOUNTER = encounters.ID
CODE [ TEXT ]
DESCRIPTION [ TEXT ]
VALUE [ REAL ]
UNITS [ TEXT ]
Please write me a SQL statement that answers the following question: List out all the observation information collected for the patient named Bella Rolfson. [/INST]
|
SELECT DISTINCT T2.DESCRIPTION, T2.VALUE, T2.UNITS FROM patients AS T1 INNER JOIN observations AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Bella' AND T1.last = 'Rolfson';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
observations :
DATE [ DATE ]
PATIENT [ TEXT ] observations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] observations.ENCOUNTER = encounters.ID
CODE [ TEXT ]
DESCRIPTION [ TEXT ]
VALUE [ REAL ]
UNITS [ TEXT ]
Please write me a SQL statement that answers the following question: List out patient names with calcium deficiency. [/INST]
|
SELECT DISTINCT T1.first, T1.last FROM patients AS T1 INNER JOIN observations AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Calcium' AND T2.VALUE < 8.6;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
observations :
DATE [ DATE ]
PATIENT [ TEXT ] observations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] observations.ENCOUNTER = encounters.ID
CODE [ TEXT ]
DESCRIPTION [ TEXT ]
VALUE [ REAL ]
UNITS [ TEXT ]
Please write me a SQL statement that answers the following question: List out 5 most common conditions for underweight patient. [/INST]
|
SELECT DISTINCT T2.DESCRIPTION, T2.VALUE, T2.UNITS FROM patients AS T1 INNER JOIN observations AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Body Mass Index' GROUP BY T2.VALUE ORDER BY COUNT(T2.VALUE) LIMIT 5;
|
[INST] Here is a database schema:
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
immunizations :
DATE [ DATE ]
PATIENT [ TEXT ] immunizations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] immunizations.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many mothers have taken immunization during prenatal visit? [/INST]
|
SELECT COUNT(DISTINCT T2.PATIENT) FROM encounters AS T1 INNER JOIN immunizations AS T2 ON T1.PATIENT = T2.PATIENT WHERE T1.REASONDESCRIPTION = 'Normal pregnancy' AND T1.DATE = T2.DATE;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: What care plans have been received by Mrs. Elly Koss during year 1970? [/INST]
|
SELECT T2.DESCRIPTION FROM patients AS T1 INNER JOIN careplans AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Elly' AND T1.last = 'Koss' AND strftime('%Y', T2.START) = '2013';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
procedures :
DATE [ DATE ]
PATIENT [ TEXT ] procedures.PATIENT = patients.patient
ENCOUNTER [ TEXT ] procedures.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: What is the care plan, procedure, medication and the patient's full name for encounter 6f2e3935-b203-493e-a9c0-f23e847b9798? [/INST]
|
SELECT DISTINCT T3.DESCRIPTION, T4.DESCRIPTION, T5.DESCRIPTION, T1.first, T1.last FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT INNER JOIN careplans AS T3 ON T1.patient = T3.PATIENT INNER JOIN procedures AS T4 ON T1.patient = T4.PATIENT INNER JOIN medications AS T5 ON T1.patient = T5.PATIENT WHERE T2.ID = '6f2e3935-b203-493e-a9c0-f23e847b9798';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: How many male patients are diagnosed with hypertension as compared to female patients? [/INST]
|
SELECT COUNT(DISTINCT CASE WHEN T2.gender = 'M' THEN T2.patient END) AS Male , COUNT(DISTINCT CASE WHEN T2.gender = 'F' THEN T2.patient END) AS Female FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Hypertension';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: How many unmarried women were checked for normal pregnancy? [/INST]
|
SELECT COUNT(DISTINCT T2.patient) FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Normal pregnancy' AND T2.gender = 'F' AND T2.marital = 'S';
|
[INST] Here is a database schema:
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
procedures :
DATE [ DATE ]
PATIENT [ TEXT ] procedures.PATIENT = patients.patient
ENCOUNTER [ TEXT ] procedures.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: List out the procedure and medicine prescribed for drug overdose patients. [/INST]
|
SELECT DISTINCT T2.DESCRIPTION, T3.DESCRIPTION FROM encounters AS T1 INNER JOIN procedures AS T2 ON T1.PATIENT = T2.PATIENT INNER JOIN medications AS T3 ON T1.PATIENT = T3.PATIENT WHERE T1.REASONDESCRIPTION = 'Drug overdose';
|
[INST] Here is a database schema:
observations :
DATE [ DATE ]
PATIENT [ TEXT ] observations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] observations.ENCOUNTER = encounters.ID
CODE [ TEXT ]
DESCRIPTION [ TEXT ]
VALUE [ REAL ]
UNITS [ TEXT ]
Please write me a SQL statement that answers the following question: What is the average body mass index for patients with higher total cholesterol? [/INST]
|
SELECT SUM(T1.VALUE) / COUNT(T1.PATIENT) FROM observations AS T1 INNER JOIN ( SELECT DISTINCT PATIENT FROM observations WHERE DESCRIPTION = 'Total Cholesterol' AND VALUE > 200 ) AS T2 ON T1.PATIENT = T2.PATIENT WHERE T1.DESCRIPTION = 'Body Mass Index';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
observations :
DATE [ DATE ]
PATIENT [ TEXT ] observations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] observations.ENCOUNTER = encounters.ID
CODE [ TEXT ]
DESCRIPTION [ TEXT ]
VALUE [ REAL ]
UNITS [ TEXT ]
Please write me a SQL statement that answers the following question: What is the difference between average glucose reading for patients in the 20s and 50s? [/INST]
|
SELECT SUM(CASE WHEN ROUND((strftime('%J', T2.DATE) - strftime('%J', T1.birthdate)) / 365) BETWEEN 20 AND 30 THEN T2.VALUE ELSE 0 END) / COUNT(CASE WHEN ROUND((strftime('%J', T2.DATE) - strftime('%J', T1.birthdate)) / 365) BETWEEN 20 AND 30 THEN T2.PATIENT END) - SUM(CASE WHEN ROUND((strftime('%J', T2.DATE) - strftime('%J', T1.birthdate)) / 365) BETWEEN 50 AND 60 THEN T2.VALUE ELSE 0 END) / COUNT(CASE WHEN ROUND((strftime('%J', T2.DATE) - strftime('%J', T1.birthdate)) / 365) BETWEEN 50 AND 60 THEN T2.PATIENT END) AS difference FROM patients AS T1 INNER JOIN observations AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Glucose';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: What is the percentage of the most common conditions for patients age 60 and above? [/INST]
|
SELECT CAST(SUM(CASE WHEN T5.DESCRIPTION = T3.DESCRIPTION THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T3.patient) FROM ( SELECT T2.DESCRIPTION, T1.patient FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE ROUND((strftime('%J', T2.START) - strftime('%J', T1.birthdate)) / 365) > 60 GROUP BY T2.DESCRIPTION ORDER BY COUNT(T2.DESCRIPTION) DESC LIMIT 1 ) AS T3 INNER JOIN patients AS T4 ON T3.patient = T4.patient INNER JOIN conditions AS T5 ON T4.patient = T5.PATIENT WHERE ROUND((strftime('%J', T5.START) - strftime('%J', T4.birthdate)) / 365) > 60;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Name the reason Walter Bahringer visited medical professionals in July 2009. [/INST]
|
SELECT T2.REASONDESCRIPTION FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Walter' AND T1.last = 'Bahringer' AND T2.DATE LIKE '2009-07%';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How old was Mr. Stacy Morar at the time of his first emergency room admission due to a drug overdose? [/INST]
|
SELECT T2.DATE - T1.birthdate AS age FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Stacy' AND T1.last = 'Morar' AND T2.DESCRIPTION = 'Emergency Room Admission' AND T2.REASONDESCRIPTION = 'Drug overdose' ORDER BY T2.DATE LIMIT 1;
|
[INST] Here is a database schema:
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: What drug is administered more often to treat child attention deficit disorder? [/INST]
|
SELECT DESCRIPTION FROM medications WHERE REASONDESCRIPTION = 'Child attention deficit disorder' GROUP BY DESCRIPTION ORDER BY COUNT(DESCRIPTION) DESC LIMIT 1;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
procedures :
DATE [ DATE ]
PATIENT [ TEXT ] procedures.PATIENT = patients.patient
ENCOUNTER [ TEXT ] procedures.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Please include the full name of the patient who received a lung transplant. [/INST]
|
SELECT T2.first, T2.last FROM procedures AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Transplant of lung (procedure)';
|
[INST] Here is a database schema:
procedures :
DATE [ DATE ]
PATIENT [ TEXT ] procedures.PATIENT = patients.patient
ENCOUNTER [ TEXT ] procedures.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many patients on average receive combined chemotherapy and radiation therapy procedures each year? [/INST]
|
SELECT CAST(COUNT(PATIENT) AS REAL) / COUNT(DISTINCT strftime('%Y', DATE)) FROM procedures WHERE DESCRIPTION = 'Combined chemotherapy and radiation therapy (procedure)';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Indicate the time frame and details of the most recent care plan suggested to Jacquelyn Shanahan. [/INST]
|
SELECT strftime('%J', T2.STOP) - strftime('%J', T2.START) AS timeFrame , T2.DESCRIPTION FROM patients AS T1 INNER JOIN careplans AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Jacquelyn' AND T1.last = 'Shanahan' ORDER BY T2.START DESC LIMIT 1;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
allergies :
START [ TEXT ]
STOP [ TEXT ]
PATIENT [ TEXT ] allergies.PATIENT = patients.patient
ENCOUNTER [ TEXT ] allergies.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Identify the allergy period for Isadora Moen and what triggered it. [/INST]
|
SELECT T2.START, T2.STOP, T2.DESCRIPTION FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Isadora' AND T1.last = 'Moen';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How old was Mrs. Laronda Bernier at the time of her most recent medical encounter? [/INST]
|
SELECT T2.DATE - T1.birthdate AS age FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Laronda' AND T1.last = 'Bernier' ORDER BY T2.DATE DESC LIMIT 1;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: What condition forced Mrs. Joye Homenick to seek medical attention in 2017? [/INST]
|
SELECT T2.DESCRIPTION FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Joye' AND T1.last = 'Homenick' AND strftime('%Y', T2.START) = '2017';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
immunizations :
DATE [ DATE ]
PATIENT [ TEXT ] immunizations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] immunizations.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: When did Mrs. Joye Homenick receive her most recent influenza seasonal vaccine? [/INST]
|
SELECT T2.DATE FROM patients AS T1 INNER JOIN immunizations AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Influenza seasonal injectable preservative free' AND T1.first = 'Joye' AND T1.last = 'Homenick' ORDER BY T2.DATE DESC LIMIT 1;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How long did Elly Koss have to take Acetaminophen 160 MG? [/INST]
|
SELECT strftime('%J', T2.STOP) - strftime('%J', T2.START) AS days FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Elly' AND last = 'Koss' AND T2.DESCRIPTION = 'Acetaminophen 160 MG';
|
[INST] Here is a database schema:
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many patients sought medical attention due to a second-degree burn? Describe the care plan recommended to them. [/INST]
|
SELECT COUNT(DISTINCT T2.PATIENT), T2.DESCRIPTION FROM encounters AS T1 INNER JOIN careplans AS T2 ON T1.PATIENT = T2.PATIENT WHERE T2.REASONDESCRIPTION = 'Second degree burn';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Among all patients who sought medical attention in 2010 due to contact dermatitis, identify the percentage of females. [/INST]
|
SELECT CAST(SUM(CASE WHEN T2.gender = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.PATIENT) FROM encounters AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE strftime('%Y', T1.DATE) = '2010' AND T1.REASONDESCRIPTION = 'Contact dermatitis';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many interactions did Lorri Simons have with medical professionals between 2010 and 2017? What percentage of encounters are attributed to prenatal visits? [/INST]
|
SELECT COUNT(T1.patient) , CAST(SUM(CASE WHEN T2.DESCRIPTION = 'Prenatal visit' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.patient) FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Lorri' AND T1.last = 'Simonis' AND strftime('%Y', T2.DATE) BETWEEN '2010' AND '2017';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: State description of medication taken by Joe Homenick. [/INST]
|
SELECT T1.DESCRIPTION FROM medications AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.first = 'Joye' AND T2.last = 'Homenick';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: What is the start date of the care plan of the patient whose maiden name is Adams? [/INST]
|
SELECT DISTINCT T1.START FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.maiden = 'Adams';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Among the male patients, who has the earliest starting date of the care plan? [/INST]
|
SELECT T2.first, T2.last FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.gender = 'M' ORDER BY T1.START LIMIT 1;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: What is the percentage of Hispanic patients who stopped their care plan in 2011? [/INST]
|
SELECT CAST(SUM(CASE WHEN T2.race = 'hispanic' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.PATIENT) FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE strftime('%Y', T1.stop) = '2011';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: State the description of the reason why Angelo Buckridge needs the care plan. [/INST]
|
SELECT DISTINCT T1.REASONDESCRIPTION FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.first = 'Angelo' AND T2.last = 'Buckridge';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Mention the description of the care plan of American patients. [/INST]
|
SELECT DISTINCT T1.DESCRIPTION FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.ethnicity = 'american';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: What are the medical encounter ids of patients who were born in Pembroke MA US? [/INST]
|
SELECT DISTINCT T1.ENCOUNTER FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.birthplace = 'Pembroke MA US';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: List out the start date of the care plan of alive patients. [/INST]
|
SELECT DISTINCT T1.START FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.deathdate IS NULL;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many white patients have the reason code of 10509002? [/INST]
|
SELECT COUNT(DISTINCT T1.PATIENT) FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.race = 'white' AND T1.REASONCODE = '10509002';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: List out full name of patients who have "Diabetic diet" in the description of the care plan. [/INST]
|
SELECT DISTINCT T2.first, T2.last FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Diabetic diet';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: List out the stop date of the care plan of dead patients. [/INST]
|
SELECT DISTINCT T1.STOP FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.deathdate IS NOT NULL AND T1.STOP IS NOT NULL;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many Italian patients have the care plan code of 304510005? [/INST]
|
SELECT COUNT(DISTINCT T2.patient) FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.ethnicity = 'italian' AND T1.CODE = '304510005';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: What is the percentage of female patients who started the care plan in 2010? [/INST]
|
SELECT CAST(SUM(CASE WHEN T2.gender = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.PATIENT) AS percentage FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE strftime('%Y', T1.START) = '2010';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many black patients stopped their care plan in 2017? [/INST]
|
SELECT COUNT(DISTINCT T2.patient) FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.race = 'black' AND strftime('%Y', T1.STOP) = '2017';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: How many male patients have prediabetes condition? [/INST]
|
SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN conditions AS T2 WHERE T2.DESCRIPTION = 'Prediabetes' AND T1.gender = 'M';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
allergies :
START [ TEXT ]
STOP [ TEXT ]
PATIENT [ TEXT ] allergies.PATIENT = patients.patient
ENCOUNTER [ TEXT ] allergies.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: List the full names of patients with nut allergy. [/INST]
|
SELECT DISTINCT T1.first, T1.last FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Allergy to nut';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: Describe the condition of patient Wilmer Koepp. [/INST]
|
SELECT T2.DESCRIPTION FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Wilmer' AND T1.last = 'Koepp';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: Among the patients with viral sinusitis condition, which patient's gender is most affected? Provide the number for each respectively. [/INST]
|
SELECT SUM(CASE WHEN T1.gender = 'F' THEN 1 ELSE 0 END), SUM(CASE WHEN T1.gender = 'M' THEN 1 ELSE 0 END) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Viral sinusitis (disorder)';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Provide the full names of patients who have been taking Penicillin V Potassium 250 MG since 1948. [/INST]
|
SELECT DISTINCT T1.first, T1.last FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Penicillin V Potassium 250 MG' AND strftime('%Y', T2.START) >= '1948';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: How many white patients whose birth year is 1935 have a stroke? [/INST]
|
SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.patient WHERE strftime('%Y', T1.birthdate) = '1935' AND T1.race = 'white' AND T2.DESCRIPTION = 'Stroke';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
immunizations :
DATE [ DATE ]
PATIENT [ TEXT ] immunizations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] immunizations.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Which conditions the patient has when receiving the IPV immunization? [/INST]
|
SELECT DISTINCT T2.DESCRIPTION FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT INNER JOIN immunizations AS T3 ON T1.patient = T3.PATIENT WHERE T3.DESCRIPTION = 'IPV';
|
[INST] Here is a database schema:
all_prevalences :
ITEM [ TEXT ] primary_key
POPULATION TYPE [ TEXT ]
OCCURRENCES [ INTEGER ]
POPULATION COUNT [ INTEGER ]
PREVALENCE RATE [ REAL ]
PREVALENCE PERCENTAGE [ REAL ]
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: List the patient ids whose disease has the most occurrences. [/INST]
|
SELECT T1.patient FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT INNER JOIN all_prevalences AS T3 ON T3.ITEM = T2.DESCRIPTION ORDER BY T3.OCCURRENCES DESC LIMIT 1;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: List all the full names of patients with a condition described as cystitis. [/INST]
|
SELECT DISTINCT T1.first, T1.last FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.patient WHERE T2.DESCRIPTION = 'Cystitis';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
immunizations :
DATE [ DATE ]
PATIENT [ TEXT ] immunizations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] immunizations.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: How many male patients have been described as immune to quadrivalent HPV? [/INST]
|
SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN immunizations AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'HPV quadrivalent' AND T1.gender = 'M';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Indicate the start date of patient Walter Bahringer's care plan. [/INST]
|
SELECT DISTINCT T2.start FROM patients AS T1 INNER JOIN careplans AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Walter' AND T1.last = 'Bahringer';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Describe the care plans of patient Major D'Amore's plan of care. [/INST]
|
SELECT DISTINCT T2.DESCRIPTION FROM patients AS T1 INNER JOIN careplans AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Major' AND T1.last = 'D''Amore';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: Calculate the percentage of male patients with viral sinusitis condition. [/INST]
|
SELECT CAST(SUM(CASE WHEN T1.gender = 'M' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.patient) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Viral sinusitis (disorder)';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Among the patients who have been using Penicillin V Potassium 250 MG, what percentage of patients are female? [/INST]
|
SELECT CAST(SUM(CASE WHEN T1.gender = 'F' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T1.patient) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Penicillin V Potassium 250 MG';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
observations :
DATE [ DATE ]
PATIENT [ TEXT ] observations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] observations.ENCOUNTER = encounters.ID
CODE [ TEXT ]
DESCRIPTION [ TEXT ]
VALUE [ REAL ]
UNITS [ TEXT ]
Please write me a SQL statement that answers the following question: Among the white patients, what is the average body height of the patients? [/INST]
|
SELECT AVG(T1.VALUE) FROM observations AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.race = 'white' AND T1.DESCRIPTION = 'Body Height';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Indicate the care plan needed for the patient living at 179 Sydni Roads, Taunton, MA 02780 US. [/INST]
|
SELECT T1.DESCRIPTION FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.address = '179 Sydni Roads Taunton MA 02780 US';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
allergies :
START [ TEXT ]
STOP [ TEXT ]
PATIENT [ TEXT ] allergies.PATIENT = patients.patient
ENCOUNTER [ TEXT ] allergies.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Provide the allergen of the Dominican patient named Dirk Languish. [/INST]
|
SELECT T1.DESCRIPTION FROM allergies AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.first = 'Dirk' AND T2.last = 'Langosh' AND T2.ethnicity = 'dominican';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
allergies :
START [ TEXT ]
STOP [ TEXT ]
PATIENT [ TEXT ] allergies.PATIENT = patients.patient
ENCOUNTER [ TEXT ] allergies.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: How many patients who are allergic to peanuts have asthma? [/INST]
|
SELECT COUNT(DISTINCT T2.patient) FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient INNER JOIN allergies AS T3 ON T2.patient = T3.PATIENT WHERE T1.DESCRIPTION = 'Asthma' AND T3.DESCRIPTION = 'Allergy to peanuts';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: Who is the 44-year-old patient diagnosed with drug overdose? [/INST]
|
SELECT T2.first, T2.last FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Drug overdose' AND ROUND((strftime('%J', T2.deathdate) - strftime('%J', T2.birthdate)) / 365) = 44;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
observations :
DATE [ DATE ]
PATIENT [ TEXT ] observations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] observations.ENCOUNTER = encounters.ID
CODE [ TEXT ]
DESCRIPTION [ TEXT ]
VALUE [ REAL ]
UNITS [ TEXT ]
Please write me a SQL statement that answers the following question: Provide the social security number of the patient with the highest systolic blood pressure. [/INST]
|
SELECT T2.ssn FROM observations AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Systolic Blood Pressure' ORDER BY T1.VALUE DESC LIMIT 1;
|
[INST] Here is a database schema:
all_prevalences :
ITEM [ TEXT ] primary_key
POPULATION TYPE [ TEXT ]
OCCURRENCES [ INTEGER ]
POPULATION COUNT [ INTEGER ]
PREVALENCE RATE [ REAL ]
PREVALENCE PERCENTAGE [ REAL ]
encounters :
ID [ TEXT ] primary_key
DATE [ DATE ]
PATIENT [ TEXT ] encounters.PATIENT = patients.patient
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: What is the care plan description of the prevalent disease with the highest prevalence percentage? [/INST]
|
SELECT T4.DESCRIPTION FROM all_prevalences AS T1 INNER JOIN conditions AS T2 ON T2.DESCRIPTION = T1.ITEM INNER JOIN encounters AS T3 ON T2.ENCOUNTER = T3.ID INNER JOIN careplans AS T4 ON T4.ENCOUNTER = T3.ID ORDER BY T1."PREVALENCE PERCENTAGE" DESC LIMIT 1;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
careplans :
ID [ TEXT ]
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] careplans.PATIENT = patients.patient
ENCOUNTER [ TEXT ] careplans.ENCOUNTER = encounters.ID
CODE [ REAL ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: What is the care plan for the patient with social security number 999-15-3685? [/INST]
|
SELECT DISTINCT T1.DESCRIPTION FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.ssn = '999-15-3685';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: Calculate the average age of the male patients that have hypertension. [/INST]
|
SELECT SUM(CASE WHEN T2.deathdate IS NULL THEN ROUND((strftime('%J', date('now')) - strftime('%J', T2.birthdate)) / 365) ELSE ROUND((strftime('%J', T2.deathdate) - strftime('%J', T2.birthdate)) / 365) END) / COUNT(T2.patient) FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Hypertension' AND T2.gender = 'M';
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: List 5 patients' name that need medication due to streptococcal sore throat disorder. [/INST]
|
SELECT DISTINCT T2.first, T2.last FROM medications AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.REASONDESCRIPTION = 'Streptococcal sore throat (disorder)' LIMIT 5;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
observations :
DATE [ DATE ]
PATIENT [ TEXT ] observations.PATIENT = patients.patient
ENCOUNTER [ TEXT ] observations.ENCOUNTER = encounters.ID
CODE [ TEXT ]
DESCRIPTION [ TEXT ]
VALUE [ REAL ]
UNITS [ TEXT ]
Please write me a SQL statement that answers the following question: Who is the patient with a body weight of 61.97 kg? [/INST]
|
SELECT T2.first, T2.last FROM observations AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Body Weight' AND T1.UNITS = 'kg' AND T1.VALUE = 61.97;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
medications :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] medications.PATIENT = patients.patient
ENCOUNTER [ TEXT ] medications.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ]
REASONCODE [ INTEGER ]
REASONDESCRIPTION [ TEXT ]
Please write me a SQL statement that answers the following question: Among the male patients, list down 5 birth dates of patients taking the medication "Penicillin V Potassium 250 MG". [/INST]
|
SELECT DISTINCT T2.birthdate FROM medications AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Penicillin V Potassium 250 MG' AND T2.gender = 'M' LIMIT 5;
|
[INST] Here is a database schema:
all_prevalences :
ITEM [ TEXT ] primary_key
POPULATION TYPE [ TEXT ]
OCCURRENCES [ INTEGER ]
POPULATION COUNT [ INTEGER ]
PREVALENCE RATE [ REAL ]
PREVALENCE PERCENTAGE [ REAL ]
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: List down the full name of Irish patients diagnosed with the prevalent diseases that have an occurrence greater than the 96% of the average occurrences of all conditions. [/INST]
|
SELECT DISTINCT T2.first, T2.last FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient INNER JOIN all_prevalences AS T3 ON T1.DESCRIPTION = T3.ITEM WHERE T2.ethnicity = 'irish' AND 100 * CAST(T3.OCCURRENCES AS REAL) / ( SELECT AVG(OCCURRENCES) FROM all_prevalences ) > 96;
|
[INST] Here is a database schema:
patients :
patient [ TEXT ] primary_key
birthdate [ DATE ]
deathdate [ DATE ]
ssn [ TEXT ]
drivers [ TEXT ]
passport [ TEXT ]
prefix [ TEXT ]
first [ TEXT ]
last [ TEXT ]
suffix [ TEXT ]
maiden [ TEXT ]
marital [ TEXT ]
race [ TEXT ]
ethnicity [ TEXT ]
gender [ TEXT ]
birthplace [ TEXT ]
address [ TEXT ]
conditions :
START [ DATE ]
STOP [ DATE ]
PATIENT [ TEXT ] conditions.PATIENT = patients.patient
ENCOUNTER [ TEXT ] conditions.ENCOUNTER = encounters.ID
CODE [ INTEGER ]
DESCRIPTION [ TEXT ] conditions.DESCRIPTION = all_prevalences.ITEM
Please write me a SQL statement that answers the following question: What is the difference between the number of married patients and the number of single patients with diabetes? [/INST]
|
SELECT SUM(CASE WHEN T2.marital = 'M' THEN 1 ELSE 0 END) - SUM(CASE WHEN T2.marital = 'S' THEN 1 ELSE 0 END) FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Diabetes';
|
[INST] Here is a database schema:
customers :
customerNumber [ INTEGER ] primary_key
customerName [ TEXT ]
contactLastName [ TEXT ]
contactFirstName [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
city [ TEXT ]
state [ TEXT ]
postalCode [ TEXT ]
country [ TEXT ]
salesRepEmployeeNumber [ INTEGER ] customers.salesRepEmployeeNumber = employees.employeeNumber
creditLimit [ REAL ]
Please write me a SQL statement that answers the following question: List the country and how many customers are there. [/INST]
|
SELECT country, COUNT(customerNumber) FROM customers GROUP BY country;
|
[INST] Here is a database schema:
products :
productCode [ TEXT ] primary_key
productName [ TEXT ]
productLine [ TEXT ] products.productLine = productlines.productLine
productScale [ TEXT ]
productVendor [ TEXT ]
productDescription [ TEXT ]
quantityInStock [ INTEGER ]
buyPrice [ REAL ]
MSRP [ REAL ]
orderdetails :
orderNumber [ INTEGER ]
productCode [ TEXT ]
quantityOrdered [ INTEGER ]
priceEach [ REAL ]
orderLineNumber [ INTEGER ]
Please write me a SQL statement that answers the following question: Which different vendor has the most amount of orders? Calculate the total estimated earnings. [/INST]
|
SELECT DISTINCT T1.productVendor, T1.MSRP - T1.buyPrice FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode GROUP BY T1.productVendor, T1.MSRP, T1.buyPrice ORDER BY COUNT(T2.quantityOrdered) DESC LIMIT 1;
|
[INST] Here is a database schema:
employees :
employeeNumber [ INTEGER ] primary_key
lastName [ TEXT ]
firstName [ TEXT ]
extension [ TEXT ]
email [ TEXT ]
officeCode [ TEXT ] employees.officeCode = offices.officeCode
reportsTo [ INTEGER ] employees.reportsTo = employees.employeeNumber
jobTitle [ TEXT ]
customers :
customerNumber [ INTEGER ] primary_key
customerName [ TEXT ]
contactLastName [ TEXT ]
contactFirstName [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
city [ TEXT ]
state [ TEXT ]
postalCode [ TEXT ]
country [ TEXT ]
salesRepEmployeeNumber [ INTEGER ] customers.salesRepEmployeeNumber = employees.employeeNumber
creditLimit [ REAL ]
payments :
customerNumber [ INTEGER ] payments.customerNumber = customers.customerNumber
checkNumber [ TEXT ]
paymentDate [ DATE ]
amount [ REAL ]
Please write me a SQL statement that answers the following question: Who is the sales agent of the distinct customer who paid the highest amount in the year 2004? [/INST]
|
SELECT DISTINCT T3.lastName, T3.firstName FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber INNER JOIN employees AS T3 ON T2.salesRepEmployeeNumber = T3.employeeNumber WHERE STRFTIME('%Y', T1.paymentDate) = '2004' ORDER BY T1.amount DESC LIMIT 1;
|
[INST] Here is a database schema:
customers :
customerNumber [ INTEGER ] primary_key
customerName [ TEXT ]
contactLastName [ TEXT ]
contactFirstName [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
city [ TEXT ]
state [ TEXT ]
postalCode [ TEXT ]
country [ TEXT ]
salesRepEmployeeNumber [ INTEGER ] customers.salesRepEmployeeNumber = employees.employeeNumber
creditLimit [ REAL ]
orders :
orderNumber [ INTEGER ] primary_key
orderDate [ DATE ]
requiredDate [ DATE ]
shippedDate [ DATE ]
status [ TEXT ]
comments [ TEXT ]
customerNumber [ INTEGER ] orders.customerNumber = customers.customerNumber
orderdetails :
orderNumber [ INTEGER ]
productCode [ TEXT ]
quantityOrdered [ INTEGER ]
priceEach [ REAL ]
orderLineNumber [ INTEGER ]
Please write me a SQL statement that answers the following question: What was the total price of the products shipped to Rovelli Gifts Distributors Ltd. between 1/1/2003 and 12/31/2003? [/INST]
|
SELECT T3.priceEach * T3.quantityOrdered FROM customers AS T1 INNER JOIN orders AS T2 ON T1.customerNumber = T2.customerNumber INNER JOIN orderdetails AS T3 ON T2.orderNumber = T3.orderNumber WHERE T1.customerName = 'Rovelli Gifts' AND T2.status = 'Shipped' AND STRFTIME('%Y', T2.shippedDate) = '2003';
|
[INST] Here is a database schema:
offices :
officeCode [ TEXT ] primary_key
city [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
state [ TEXT ]
country [ TEXT ]
postalCode [ TEXT ]
territory [ TEXT ]
employees :
employeeNumber [ INTEGER ] primary_key
lastName [ TEXT ]
firstName [ TEXT ]
extension [ TEXT ]
email [ TEXT ]
officeCode [ TEXT ] employees.officeCode = offices.officeCode
reportsTo [ INTEGER ] employees.reportsTo = employees.employeeNumber
jobTitle [ TEXT ]
Please write me a SQL statement that answers the following question: How many employees are there in Sydney? [/INST]
|
SELECT COUNT(employeeNumber) FROM employees WHERE officeCode = ( SELECT officeCode FROM offices WHERE city = 'Sydney' );
|
[INST] Here is a database schema:
offices :
officeCode [ TEXT ] primary_key
city [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
state [ TEXT ]
country [ TEXT ]
postalCode [ TEXT ]
territory [ TEXT ]
employees :
employeeNumber [ INTEGER ] primary_key
lastName [ TEXT ]
firstName [ TEXT ]
extension [ TEXT ]
email [ TEXT ]
officeCode [ TEXT ] employees.officeCode = offices.officeCode
reportsTo [ INTEGER ] employees.reportsTo = employees.employeeNumber
jobTitle [ TEXT ]
Please write me a SQL statement that answers the following question: Which sales representatives in New York city whose leader is Anthony Bow with the employee number is 1143? Indicate their employee numbers. [/INST]
|
SELECT T1.employeeNumber FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T1.reportsTo = 1143 AND T2.city = 'NYC';
|
[INST] Here is a database schema:
customers :
customerNumber [ INTEGER ] primary_key
customerName [ TEXT ]
contactLastName [ TEXT ]
contactFirstName [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
city [ TEXT ]
state [ TEXT ]
postalCode [ TEXT ]
country [ TEXT ]
salesRepEmployeeNumber [ INTEGER ] customers.salesRepEmployeeNumber = employees.employeeNumber
creditLimit [ REAL ]
payments :
customerNumber [ INTEGER ] payments.customerNumber = customers.customerNumber
checkNumber [ TEXT ]
paymentDate [ DATE ]
amount [ REAL ]
Please write me a SQL statement that answers the following question: What is the average, highest and lowest annual payments collected between 1/1/2003 to 12/31/2005? [/INST]
|
SELECT CAST(SUM(T1.amount) AS REAL) / 3, MAX(T1.amount) , MIN(T1.amount) FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.paymentDate BETWEEN '2003-01-01' AND '2005-12-31';
|
[INST] Here is a database schema:
customers :
customerNumber [ INTEGER ] primary_key
customerName [ TEXT ]
contactLastName [ TEXT ]
contactFirstName [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
city [ TEXT ]
state [ TEXT ]
postalCode [ TEXT ]
country [ TEXT ]
salesRepEmployeeNumber [ INTEGER ] customers.salesRepEmployeeNumber = employees.employeeNumber
creditLimit [ REAL ]
payments :
customerNumber [ INTEGER ] payments.customerNumber = customers.customerNumber
checkNumber [ TEXT ]
paymentDate [ DATE ]
amount [ REAL ]
Please write me a SQL statement that answers the following question: Which countries do the top 5 highest paying customers in a single payment come from? Indicate their entire address. [/INST]
|
SELECT DISTINCT T2.country, T2.addressLine1, T2.addressLine2 FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber ORDER BY T1.amount DESC LIMIT 5;
|
[INST] Here is a database schema:
customers :
customerNumber [ INTEGER ] primary_key
customerName [ TEXT ]
contactLastName [ TEXT ]
contactFirstName [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
city [ TEXT ]
state [ TEXT ]
postalCode [ TEXT ]
country [ TEXT ]
salesRepEmployeeNumber [ INTEGER ] customers.salesRepEmployeeNumber = employees.employeeNumber
creditLimit [ REAL ]
payments :
customerNumber [ INTEGER ] payments.customerNumber = customers.customerNumber
checkNumber [ TEXT ]
paymentDate [ DATE ]
amount [ REAL ]
Please write me a SQL statement that answers the following question: How many checks were issued by Euro+ Shopping Channel in the year 2004? [/INST]
|
SELECT COUNT(T1.checkNumber) FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE customerName = 'Euro+ Shopping Channel' AND STRFTIME('%Y', T1.paymentDate) = '2004';
|
[INST] Here is a database schema:
products :
productCode [ TEXT ] primary_key
productName [ TEXT ]
productLine [ TEXT ] products.productLine = productlines.productLine
productScale [ TEXT ]
productVendor [ TEXT ]
productDescription [ TEXT ]
quantityInStock [ INTEGER ]
buyPrice [ REAL ]
MSRP [ REAL ]
orderdetails :
orderNumber [ INTEGER ]
productCode [ TEXT ]
quantityOrdered [ INTEGER ]
priceEach [ REAL ]
orderLineNumber [ INTEGER ]
Please write me a SQL statement that answers the following question: Of all the classic cars, with a product scale of 1:18, which product is the most ordered product by customers? [/INST]
|
SELECT T1.productName FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode WHERE T1.productScale = '1:18' AND T1.productLine = 'Classic Cars' GROUP BY T1.productName ORDER BY SUM(T2.quantityOrdered) DESC LIMIT 1;
|
[INST] Here is a database schema:
customers :
customerNumber [ INTEGER ] primary_key
customerName [ TEXT ]
contactLastName [ TEXT ]
contactFirstName [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
city [ TEXT ]
state [ TEXT ]
postalCode [ TEXT ]
country [ TEXT ]
salesRepEmployeeNumber [ INTEGER ] customers.salesRepEmployeeNumber = employees.employeeNumber
creditLimit [ REAL ]
payments :
customerNumber [ INTEGER ] payments.customerNumber = customers.customerNumber
checkNumber [ TEXT ]
paymentDate [ DATE ]
amount [ REAL ]
Please write me a SQL statement that answers the following question: How many customers have a credit limit of not more than 100,000 and which customer made the highest total payment amount for the year 2004? [/INST]
|
SELECT ( SELECT COUNT(customerNumber) FROM customers WHERE creditLimit <= 100000 AND customerNumber IN ( SELECT customerNumber FROM payments WHERE STRFTIME('%Y', paymentDate) = '2004' ) ), T1.customerName FROM customers AS T1 INNER JOIN payments AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.creditLimit <= 100000 AND STRFTIME('%Y', T2.paymentDate) = '2004' GROUP BY T1.customerNumber, T1.customerName ORDER BY SUM(T2.amount) DESC LIMIT 1;
|
[INST] Here is a database schema:
offices :
officeCode [ TEXT ] primary_key
city [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
state [ TEXT ]
country [ TEXT ]
postalCode [ TEXT ]
territory [ TEXT ]
employees :
employeeNumber [ INTEGER ] primary_key
lastName [ TEXT ]
firstName [ TEXT ]
extension [ TEXT ]
email [ TEXT ]
officeCode [ TEXT ] employees.officeCode = offices.officeCode
reportsTo [ INTEGER ] employees.reportsTo = employees.employeeNumber
jobTitle [ TEXT ]
customers :
customerNumber [ INTEGER ] primary_key
customerName [ TEXT ]
contactLastName [ TEXT ]
contactFirstName [ TEXT ]
phone [ TEXT ]
addressLine1 [ TEXT ]
addressLine2 [ TEXT ]
city [ TEXT ]
state [ TEXT ]
postalCode [ TEXT ]
country [ TEXT ]
salesRepEmployeeNumber [ INTEGER ] customers.salesRepEmployeeNumber = employees.employeeNumber
creditLimit [ REAL ]
payments :
customerNumber [ INTEGER ] payments.customerNumber = customers.customerNumber
checkNumber [ TEXT ]
paymentDate [ DATE ]
amount [ REAL ]
Please write me a SQL statement that answers the following question: Which of the customers, whose Tokyo-based sales representative reports to the Vice President of Sales whose employee number is 1056, has paid the highest payment? List the customer's name, the contact person and calculate the total amount of that customer's total payments. [/INST]
|
SELECT T2.customerName, T2.contactFirstName, T2.contactLastName, SUM(T3.amount) FROM employees AS T1 INNER JOIN customers AS T2 ON T2.salesRepEmployeeNumber = T1.employeeNumber INNER JOIN payments AS T3 ON T2.customerNumber = T3.customerNumber INNER JOIN offices AS T4 ON T1.officeCode = T4.officeCode WHERE T4.city = 'Tokyo' AND T1.reportsTo = 1056 GROUP BY T2.customerName, T2.contactFirstName, T2.contactLastName ORDER BY amount DESC LIMIT 1;
|
[INST] Here is a database schema:
products :
productCode [ TEXT ] primary_key
productName [ TEXT ]
productLine [ TEXT ] products.productLine = productlines.productLine
productScale [ TEXT ]
productVendor [ TEXT ]
productDescription [ TEXT ]
quantityInStock [ INTEGER ]
buyPrice [ REAL ]
MSRP [ REAL ]
orderdetails :
orderNumber [ INTEGER ]
productCode [ TEXT ]
quantityOrdered [ INTEGER ]
priceEach [ REAL ]
orderLineNumber [ INTEGER ]
Please write me a SQL statement that answers the following question: Which two products has the highest and lowest expected profits? Determine the total price for each product in terms of the largest quantity that was ordered. [/INST]
|
SELECT T2.productName, SUM(T1.quantityOrdered * T1.priceEach) FROM orderdetails AS T1 INNER JOIN ( SELECT productCode, productName FROM products ORDER BY MSRP - buyPrice DESC LIMIT 1 ) AS T2 ON T1.productCode = T2.productCode UNION SELECT T2.productName, SUM(quantityOrdered * priceEach) FROM orderdetails AS T1 INNER JOIN ( SELECT productCode, productName FROM products ORDER BY MSRP - buyPrice ASC LIMIT 1 ) AS T2 ON T1.productCode = T2.productCode;
|
[INST] Here is a database schema:
orders :
orderNumber [ INTEGER ] primary_key
orderDate [ DATE ]
requiredDate [ DATE ]
shippedDate [ DATE ]
status [ TEXT ]
comments [ TEXT ]
customerNumber [ INTEGER ] orders.customerNumber = customers.customerNumber
orderdetails :
orderNumber [ INTEGER ]
productCode [ TEXT ]
quantityOrdered [ INTEGER ]
priceEach [ REAL ]
orderLineNumber [ INTEGER ]
Please write me a SQL statement that answers the following question: How many different orders with a total price greater than 4000 are cancelled? [/INST]
|
SELECT COUNT(DISTINCT T1.orderNumber) FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber WHERE T1.quantityOrdered * T1.priceEach > 4000 AND T2.status = 'Cancelled';
|
[INST] Here is a database schema:
orders :
orderNumber [ INTEGER ] primary_key
orderDate [ DATE ]
requiredDate [ DATE ]
shippedDate [ DATE ]
status [ TEXT ]
comments [ TEXT ]
customerNumber [ INTEGER ] orders.customerNumber = customers.customerNumber
orderdetails :
orderNumber [ INTEGER ]
productCode [ TEXT ]
quantityOrdered [ INTEGER ]
priceEach [ REAL ]
orderLineNumber [ INTEGER ]
Please write me a SQL statement that answers the following question: How many distinct orders were there in 2003 when the quantity ordered was less than 30? [/INST]
|
SELECT COUNT(DISTINCT T1.orderNumber) FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber WHERE T1.quantityOrdered < 30 AND STRFTIME('%Y', T2.orderDate) = '2003';
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.