data_source
stringclasses
1 value
prompt
listlengths
2
2
ability
stringclasses
1 value
reward_model
dict
extra_info
dict
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Diabetes', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Diabetes', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Diabetes', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndiabetes that started in 1988 refers to DESCRIPTION = 'Diabetes' from conditions and START like '1988%';\nHow many patients have diabetes that started in 1988?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(PATIENT) FROM conditions WHERE DESCRIPTION = 'Diabetes' AND strftime('%Y', START) = '1988'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(PATIENT) FROM conditions WHERE DESCRIPTION = 'Diabetes' AND strftime('%Y', START) = '1988'", "index": 700, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Diabetes', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Diabetes', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Diabetes', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndiabetes that started in 1988 refers to DESCRIPTION = 'Diabetes' from conditions and START like '1988%';\nHow many patients have diabetes that started in 1988?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Hypertension', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Hypertension', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nid of the patient refers to PATIENT from conditions;  hypertension refers to DESCRIPTION = 'Hypertension'; most recently refers to MAX(START);\nWhat is the id of the patient whose hypertension started most recently?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT PATIENT FROM conditions WHERE START = ( SELECT MAX(START) FROM conditions WHERE DESCRIPTION = 'Hypertension' )", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT PATIENT FROM conditions WHERE START = ( SELECT MAX(START) FROM conditions WHERE DESCRIPTION = 'Hypertension' )", "index": 701, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Hypertension', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Hypertension', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nid of the patient refers to PATIENT from conditions;  hypertension refers to DESCRIPTION = 'Hypertension'; most recently refers to MAX(START);\nWhat is the id of the patient whose hypertension started most recently?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nid of the tallest patient/s refers to PATIENT from observations where MAX(DESCRIPTION = 'Body Height');\nWhat is/are the ids of the tallest patient/s?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT PATIENT FROM observations WHERE DESCRIPTION = 'Body Height' AND UNITS = 'cm' ORDER BY VALUE DESC LIMIT 1", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT PATIENT FROM observations WHERE DESCRIPTION = 'Body Height' AND UNITS = 'cm' ORDER BY VALUE DESC LIMIT 1", "index": 702, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nid of the tallest patient/s refers to PATIENT from observations where MAX(DESCRIPTION = 'Body Height');\nWhat is/are the ids of the tallest patient/s?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Ibuprofen 200 MG Oral Tablet', 'Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Ibuprofen 200 Mg Oral Tablet', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['M', 'S']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['M', 'F']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nIbuprofen 200mg Oral Tablet refers to DESCRIPTION = 'Ibuprofen 200 MG Oral Tablet' from medications; started in 2016 refers to START like '2016%'; Dominican patients refer to ethnicity = 'dominican'; stopped taking the medicine after exactly one month refers to SUBTRACT(strftime('%m', STOP), strftime('%m', START)) = 1;\nAmong the patients that started taking Ibuprofen 200mg Oral Tablet in 2016, how many Dominican patients stopped taking the medicine after exactly one month?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Ibuprofen 200 MG Oral Tablet' AND T1.ethnicity = 'dominican' AND strftime('%Y', T2.START) = '2016' AND strftime('%m', T2.STOP) - strftime('%m', T2.START) = 1", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Ibuprofen 200 MG Oral Tablet' AND T1.ethnicity = 'dominican' AND strftime('%Y', T2.START) = '2016' AND strftime('%m', T2.STOP) - strftime('%m', T2.START) = 1", "index": 703, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Ibuprofen 200 MG Oral Tablet', 'Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Ibuprofen 200 Mg Oral Tablet', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['M', 'S']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['M', 'F']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nIbuprofen 200mg Oral Tablet refers to DESCRIPTION = 'Ibuprofen 200 MG Oral Tablet' from medications; started in 2016 refers to START like '2016%'; Dominican patients refer to ethnicity = 'dominican'; stopped taking the medicine after exactly one month refers to SUBTRACT(strftime('%m', STOP), strftime('%m', START)) = 1;\nAmong the patients that started taking Ibuprofen 200mg Oral Tablet in 2016, how many Dominican patients stopped taking the medicine after exactly one month?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Pneumonia', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Pneumonia', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Pneumonia', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Pneumonia', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\npatients born in 1920s refer to patient where birthdate like '192%'; pneumonia refers to DESCRIPTION = 'Pneumonia' from conditions;\nHow many of the patients born in 1920s had pneumonia?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE DESCRIPTION = 'Pneumonia' AND strftime('%Y', T1.birthdate) LIKE '192%'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE DESCRIPTION = 'Pneumonia' AND strftime('%Y', T1.birthdate) LIKE '192%'", "index": 704, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Pneumonia', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Pneumonia', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Pneumonia', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Pneumonia', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\npatients born in 1920s refer to patient where birthdate like '192%'; pneumonia refers to DESCRIPTION = 'Pneumonia' from conditions;\nHow many of the patients born in 1920s had pneumonia?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nids of the patients refer to PATIENT from conditions; condition that has a prevalence percentage of 18.8% refers to PREVALENCE PERCENTAGE = 18.8;\nList the ids of all the patients with condition that has a prevalence percentage of 18.8%.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DISTINCT T1.PATIENT FROM conditions AS T1 INNER JOIN all_prevalences AS T2 ON lower(T2.ITEM) = lower(T1.DESCRIPTION) WHERE T2.\"PREVALENCE PERCENTAGE\" = CAST(18.8 AS float)", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT DISTINCT T1.PATIENT FROM conditions AS T1 INNER JOIN all_prevalences AS T2 ON lower(T2.ITEM) = lower(T1.DESCRIPTION) WHERE T2.\"PREVALENCE PERCENTAGE\" = CAST(18.8 AS float)", "index": 705, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nids of the patients refer to PATIENT from conditions; condition that has a prevalence percentage of 18.8% refers to PREVALENCE PERCENTAGE = 18.8;\nList the ids of all the patients with condition that has a prevalence percentage of 18.8%.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Tyree', 'Rosamaria', 'Loan']\n last text, -- example: ['Eichmann', 'Pfannerstill', 'Bashirian']\n marital text, -- example: ['S', 'M']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nconditions refer to DESCRIPTION from conditions;\nHow many conditions did Tyree Eichmann have?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(DISTINCT T2.DESCRIPTION) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Tyree' AND T1.last = 'Eichmann'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(DISTINCT T2.DESCRIPTION) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Tyree' AND T1.last = 'Eichmann'", "index": 706, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Tyree', 'Rosamaria', 'Loan']\n last text, -- example: ['Eichmann', 'Pfannerstill', 'Bashirian']\n marital text, -- example: ['S', 'M']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nconditions refer to DESCRIPTION from conditions;\nHow many conditions did Tyree Eichmann have?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['meningococcal MCV4P', 'Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Viral Sinusitis (Disorder)', 'Sinusitis (Disorder)', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nimmunized with meningococcal MCV4P refers to DESCRIPTION = 'meningococcal MCV4P' from immunizations; viral sinusitis disorder refers to DESCRIPTION = 'Viral sinusitis (disorder)' from conditions;\nAmong the patients who were immunized with meningococcal MCV4P, how many have viral sinusitis disorder after getting the immunization?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(DISTINCT T1.patient) FROM immunizations AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T1.DESCRIPTION = 'meningococcal MCV4P' AND T2.DESCRIPTION = 'Viral sinusitis (disorder)'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(DISTINCT T1.patient) FROM immunizations AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T1.DESCRIPTION = 'meningococcal MCV4P' AND T2.DESCRIPTION = 'Viral sinusitis (disorder)'", "index": 707, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['meningococcal MCV4P', 'Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Viral Sinusitis (Disorder)', 'Sinusitis (Disorder)', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nimmunized with meningococcal MCV4P refers to DESCRIPTION = 'meningococcal MCV4P' from immunizations; viral sinusitis disorder refers to DESCRIPTION = 'Viral sinusitis (disorder)' from conditions;\nAmong the patients who were immunized with meningococcal MCV4P, how many have viral sinusitis disorder after getting the immunization?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Hypertension', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Giovanni', 'Russel', 'Rosamaria', 'Loan']\n last text, -- example: ['Russel', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Hypertension', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nage refers to SUBTRACT(strftime('%Y', deathdate), strftime('%Y', birthdate)); hypertension refers to conditions where DESCRIPTION = 'Hypertension';\nWhat is the age of the patient with hypertension named Giovanni Russel?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT strftime('%Y', T2.deathdate) - strftime('%Y', T2.birthdate) AS age FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.first = 'Giovanni' AND T2.last = 'Russel' AND T1.DESCRIPTION = 'Hypertension'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT strftime('%Y', T2.deathdate) - strftime('%Y', T2.birthdate) AS age FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.first = 'Giovanni' AND T2.last = 'Russel' AND T1.DESCRIPTION = 'Hypertension'", "index": 708, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Hypertension', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Giovanni', 'Russel', 'Rosamaria', 'Loan']\n last text, -- example: ['Russel', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Hypertension', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nage refers to SUBTRACT(strftime('%Y', deathdate), strftime('%Y', birthdate)); hypertension refers to conditions where DESCRIPTION = 'Hypertension';\nWhat is the age of the patient with hypertension named Giovanni Russel?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to peanuts', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['asian', 'black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Allergy To Peanuts', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nAsian refers to race like 'asian%'; allergic to peanuts refers to allergies where DESCRIPTION = 'Allergy to peanuts'; \n\nWhat is the total number of Asian patients who are allergic to peanuts?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(T2.patient) FROM allergies AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Allergy to peanuts' AND T2.race = 'asian'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(T2.patient) FROM allergies AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Allergy to peanuts' AND T2.race = 'asian'", "index": 709, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to peanuts', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['asian', 'black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Allergy To Peanuts', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nAsian refers to race like 'asian%'; allergic to peanuts refers to allergies where DESCRIPTION = 'Allergy to peanuts'; \n\nWhat is the total number of Asian patients who are allergic to peanuts?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nWho is the patient involved in the care plan with code 311791003?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T2.first, T2.last FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.CODE = 315043002", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT T2.first, T2.last FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.CODE = 315043002", "index": 710, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nWho is the patient involved in the care plan with code 311791003?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nif deathdate is not null, it means this patient died; condition refers to DESCRIPTION from conditions; the oldest patient refers to MAX(SUBTRACT(strftime('%Y', deathdate), strftime('%Y', birthdate)));\nAmong the patients that died, what is the condition of the oldest patient?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.DESCRIPTION FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.deathdate IS NOT NULL ORDER BY strftime('%Y', T2.deathdate) - strftime('%Y', T2.birthdate) DESC LIMIT 1", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT T1.DESCRIPTION FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.deathdate IS NOT NULL ORDER BY strftime('%Y', T2.deathdate) - strftime('%Y', T2.birthdate) DESC LIMIT 1", "index": 711, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nif deathdate is not null, it means this patient died; condition refers to DESCRIPTION from conditions; the oldest patient refers to MAX(SUBTRACT(strftime('%Y', deathdate), strftime('%Y', birthdate)));\nAmong the patients that died, what is the condition of the oldest patient?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nWhat is the code of the prevalent disease with the highest occurrences?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T2.code FROM all_prevalences AS T1 INNER JOIN conditions AS T2 ON T1.ITEM = T2.DESCRIPTION ORDER BY T1.OCCURRENCES DESC LIMIT 1", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT T2.code FROM all_prevalences AS T1 INNER JOIN conditions AS T2 ON T1.ITEM = T2.DESCRIPTION ORDER BY T1.OCCURRENCES DESC LIMIT 1", "index": 712, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nWhat is the code of the prevalent disease with the highest occurrences?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n first text, -- example: ['Rosamaria', 'Loan']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['asian', 'black', 'white']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Acute Bronchitis (Disorder)', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nDIVIDE(COUNT(PATIENT where gender = 'F' and race = 'asian'), COUNT(PATIENT)) as percentage where DESCRIPTION = 'Acute bronchitis (disorder)' ;\nAmong the patients with acute bronchitis, what is the percentage of Asian women?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT CAST(SUM(CASE WHEN T2.gender = 'F' AND T2.race = 'asian' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T2.gender) FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Acute bronchitis (disorder)'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT CAST(SUM(CASE WHEN T2.gender = 'F' AND T2.race = 'asian' THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(T2.gender) FROM conditions AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.DESCRIPTION = 'Acute bronchitis (disorder)'", "index": 713, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n first text, -- example: ['Rosamaria', 'Loan']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['asian', 'black', 'white']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Acute Bronchitis (Disorder)', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nDIVIDE(COUNT(PATIENT where gender = 'F' and race = 'asian'), COUNT(PATIENT)) as percentage where DESCRIPTION = 'Acute bronchitis (disorder)' ;\nAmong the patients with acute bronchitis, what is the percentage of Asian women?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Elly', 'Rosamaria', 'Loan']\n last text, -- example: ['Koss', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Koss', 'Schuster', 'Schaden']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Weight', 'Body Height']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nbody weight VALUE and UNITS where DESCRIPTION = 'Body Weight' from observations;\nProvide the body weight of Elly Koss in every observation.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T2.DESCRIPTION, T2.VALUE, T2.UNITS FROM patients AS T1 INNER JOIN observations AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Elly' AND T1.last = 'Koss' AND T2.DESCRIPTION = 'Body Weight'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT T2.DESCRIPTION, T2.VALUE, T2.UNITS FROM patients AS T1 INNER JOIN observations AS T2 ON T1.patient = T2.PATIENT WHERE T1.first = 'Elly' AND T1.last = 'Koss' AND T2.DESCRIPTION = 'Body Weight'", "index": 714, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Elly', 'Rosamaria', 'Loan']\n last text, -- example: ['Koss', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Koss', 'Schuster', 'Schaden']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Weight', 'Body Height']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nbody weight VALUE and UNITS where DESCRIPTION = 'Body Weight' from observations;\nProvide the body weight of Elly Koss in every observation.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Allergy To Soya', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to soya', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nallergy to soy refers to allergies where DESCRIPTION = 'Allergy to soya';\nName the patients who had an allergy to soy.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.first, T1.last FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Allergy to soya'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT T1.first, T1.last FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Allergy to soya'", "index": 715, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Allergy To Soya', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to soya', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nallergy to soy refers to allergies where DESCRIPTION = 'Allergy to soya';\nName the patients who had an allergy to soy.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Clopidogrel', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Clopidogrel 75 MG Oral Tablet', 'Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['years', 'cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nWho implies the full name of the patient which refers to first, last; Clopidogrel 75 MG Oral Tablet refers to medications where DESCRIPTION = 'Clopidogrel 75 MG Oral Tablet'; for over 10 years refers to SUBTRACT(strftime('%Y', STOP), strftime('%Y', START)) > 10;\nWho had to take Clopidogrel 75 MG Oral Tablet for over 10 years?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.first, T1.last FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Clopidogrel 75 MG Oral Tablet' AND strftime('%Y', T2.STOP) - strftime('%Y', T2.START) > 10", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT T1.first, T1.last FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Clopidogrel 75 MG Oral Tablet' AND strftime('%Y', T2.STOP) - strftime('%Y', T2.START) > 10", "index": 716, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Clopidogrel', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Clopidogrel 75 MG Oral Tablet', 'Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['years', 'cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nWho implies the full name of the patient which refers to first, last; Clopidogrel 75 MG Oral Tablet refers to medications where DESCRIPTION = 'Clopidogrel 75 MG Oral Tablet'; for over 10 years refers to SUBTRACT(strftime('%Y', STOP), strftime('%Y', START)) > 10;\nWho had to take Clopidogrel 75 MG Oral Tablet for over 10 years?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Third degree burn', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Third Degree Burn', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nprocedures refer to DESCRIPTION from procedures; medications refers to DESCRIPTION from medications; third-degree burn refers to conditions where DESCRIPTION = 'Third degree burn';\nWhich procedures and medications were received by the patient with the third-degree burn?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DISTINCT T1.DESCRIPTION, T3.DESCRIPTION FROM procedures AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT INNER JOIN medications AS T3 ON T2.patient = T3.PATIENT WHERE T2.DESCRIPTION = 'Third degree burn'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT DISTINCT T1.DESCRIPTION, T3.DESCRIPTION FROM procedures AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT INNER JOIN medications AS T3 ON T2.patient = T3.PATIENT WHERE T2.DESCRIPTION = 'Third degree burn'", "index": 717, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Third degree burn', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Third Degree Burn', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nprocedures refer to DESCRIPTION from procedures; medications refers to DESCRIPTION from medications; third-degree burn refers to conditions where DESCRIPTION = 'Third degree burn';\nWhich procedures and medications were received by the patient with the third-degree burn?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Normal Pregnancy', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Normal pregnancy', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Normal pregnancy', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Normal pregnancy', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Normal pregnancy', 'Acute bronchitis (disorder)']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nencountered normal pregnancy refers to encounters where REASONDESCRIPTION = 'Normal pregnancy';\nList down the first name of patients who encountered normal pregnancy.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DISTINCT T1.first FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT WHERE T2.REASONDESCRIPTION = 'Normal pregnancy'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT DISTINCT T1.first FROM patients AS T1 INNER JOIN encounters AS T2 ON T1.patient = T2.PATIENT WHERE T2.REASONDESCRIPTION = 'Normal pregnancy'", "index": 718, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Normal Pregnancy', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Normal pregnancy', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Normal pregnancy', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Normal pregnancy', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Normal pregnancy', 'Acute bronchitis (disorder)']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nencountered normal pregnancy refers to encounters where REASONDESCRIPTION = 'Normal pregnancy';\nList down the first name of patients who encountered normal pregnancy.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Stroke', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Stroke', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n marital text, -- example: ['M', 'S']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['M', 'F']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Stroke', 'Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Stroke', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstroke refers to conditions where DESCRIPTION = 'Stroke'; married refers to the marital status of the patient in which marital = 'M';\nHow many stroke patients have married?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Stroke' AND T1.marital = 'M'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Stroke' AND T1.marital = 'M'", "index": 719, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Stroke', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Stroke', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n marital text, -- example: ['M', 'S']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['M', 'F']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Stroke', 'Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Stroke', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstroke refers to conditions where DESCRIPTION = 'Stroke'; married refers to the marital status of the patient in which marital = 'M';\nHow many stroke patients have married?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nList down the address of patients who have billable period in 2010.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DISTINCT T1.address FROM patients AS T1 INNER JOIN claims AS T2 ON T1.patient = T2.PATIENT WHERE T2.BILLABLEPERIOD LIKE '2010%'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT DISTINCT T1.address FROM patients AS T1 INNER JOIN claims AS T2 ON T1.patient = T2.PATIENT WHERE T2.BILLABLEPERIOD LIKE '2010%'", "index": 720, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nList down the address of patients who have billable period in 2010.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n last text, -- example: ['White', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n race text, -- example: ['white', 'black']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nkind of allergy is most common refers to MAX(COUNT(DESCRIPTION)) from allergies; white refers to race = 'white';\nWhat kind of allergy is most common among white people?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T2.DESCRIPTION FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T1.race = 'white' GROUP BY T2.DESCRIPTION ORDER BY COUNT(T2.DESCRIPTION) DESC LIMIT 1", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT T2.DESCRIPTION FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T1.race = 'white' GROUP BY T2.DESCRIPTION ORDER BY COUNT(T2.DESCRIPTION) DESC LIMIT 1", "index": 721, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n last text, -- example: ['White', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n race text, -- example: ['white', 'black']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nkind of allergy is most common refers to MAX(COUNT(DESCRIPTION)) from allergies; white refers to race = 'white';\nWhat kind of allergy is most common among white people?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Coronary Heart Disease', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Coronary Heart Disease', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Coronary Heart Disease', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Coronary Heart Disease', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\npatients who have stopped taking medication for 'coronary heart disease' refer to PATIENT where REASONDESCRIPTION = 'Coronary Heart Disease' and STOP is not null from medications; if deathdate is null, it means this patient is still alive;\nHow many of the patients who have stopped taking medication for 'coronary heart disease' are still alive?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(DISTINCT T2.patient) FROM medications AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.REASONDESCRIPTION = 'Coronary Heart Disease' AND T1.STOP IS NOT NULL AND T2.deathdate IS NULL", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(DISTINCT T2.patient) FROM medications AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T1.REASONDESCRIPTION = 'Coronary Heart Disease' AND T1.STOP IS NOT NULL AND T2.deathdate IS NULL", "index": 722, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Coronary Heart Disease', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Coronary Heart Disease', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Coronary Heart Disease', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Coronary Heart Disease', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\npatients who have stopped taking medication for 'coronary heart disease' refer to PATIENT where REASONDESCRIPTION = 'Coronary Heart Disease' and STOP is not null from medications; if deathdate is null, it means this patient is still alive;\nHow many of the patients who have stopped taking medication for 'coronary heart disease' are still alive?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Myocardial Infarction', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n ethnicity text, -- example: ['irish', 'dominican', 'american']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Myocardial Infarction', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Myocardial Infarction', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Myocardial Infarction', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntake medication for myocardial infarction refers to medications.REASONDESCRIPTION = 'Myocardial Infarction';\nHow many patients of Irish ethnicity take medication for 'myocardial infarction'?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.REASONDESCRIPTION = 'Myocardial Infarction' AND T1.ethnicity = 'irish'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.REASONDESCRIPTION = 'Myocardial Infarction' AND T1.ethnicity = 'irish'", "index": 723, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Myocardial Infarction', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n ethnicity text, -- example: ['irish', 'dominican', 'american']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Myocardial Infarction', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Myocardial Infarction', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Myocardial Infarction', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntake medication for myocardial infarction refers to medications.REASONDESCRIPTION = 'Myocardial Infarction';\nHow many patients of Irish ethnicity take medication for 'myocardial infarction'?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Nitroglycerin', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nwomen refers to gender = 'F'; Nitroglycerin 0.4 MG/ACTUAT [Nitrolingual] refers to medications.DESCRIPTION = 'Nitroglycerin 0.4 MG/ACTUAT [Nitrolingual]'\nHow many women need to take 'Nitroglycerin 0.4 MG/ACTUAT [Nitrolingual]'?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Nitroglycerin 0.4 MG/ACTUAT [Nitrolingual]' AND T1.gender = 'F'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT COUNT(DISTINCT T1.patient) FROM patients AS T1 INNER JOIN medications AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Nitroglycerin 0.4 MG/ACTUAT [Nitrolingual]' AND T1.gender = 'F'", "index": 724, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Nitroglycerin', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nwomen refers to gender = 'F'; Nitroglycerin 0.4 MG/ACTUAT [Nitrolingual] refers to medications.DESCRIPTION = 'Nitroglycerin 0.4 MG/ACTUAT [Nitrolingual]'\nHow many women need to take 'Nitroglycerin 0.4 MG/ACTUAT [Nitrolingual]'?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Weight', 'Body Height']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['kg', 'cm']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['asian', 'black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage = AVG(observations.VALUE WHERE observations.DESCRIPTION = 'Body Weight' AND observations.UNITS = 'kg'); body weight refers to observations.DESCRIPTION = 'Body Weight'; Asian refers to race = 'asian';\nWhat is the average body weight of Asian patients?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 725, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Weight', 'Body Height']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['kg', 'cm']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['asian', 'black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage = AVG(observations.VALUE WHERE observations.DESCRIPTION = 'Body Weight' AND observations.UNITS = 'kg'); body weight refers to observations.DESCRIPTION = 'Body Weight'; Asian refers to race = 'asian';\nWhat is the average body weight of Asian patients?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Latex allergy', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Latex Allergy', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nSocial Security numbers refers to ssn; latex allergies refers to allergies.DESCRIPTION = 'Latex allergy';\nWrite down the Social Security numbers of patients who have latex allergies.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.ssn FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Latex allergy'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT T1.ssn FROM patients AS T1 INNER JOIN allergies AS T2 ON T1.patient = T2.PATIENT WHERE T2.DESCRIPTION = 'Latex allergy'", "index": 726, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Latex allergy', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Latex Allergy', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nSocial Security numbers refers to ssn; latex allergies refers to allergies.DESCRIPTION = 'Latex allergy';\nWrite down the Social Security numbers of patients who have latex allergies.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Isadora', 'Rosamaria', 'Loan']\n last text, -- example: ['Moen', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nhow long the allergies last = SUBTRACT(allergies.STOP, allergies.START); kind of allergy refers to allergies.DESCRIPTION;\nHow long did Isadora Moen's allergy last? Tell me what kind of allergy she has.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 727, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Isadora', 'Rosamaria', 'Loan']\n last text, -- example: ['Moen', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nhow long the allergies last = SUBTRACT(allergies.STOP, allergies.START); kind of allergy refers to allergies.DESCRIPTION;\nHow long did Isadora Moen's allergy last? Tell me what kind of allergy she has.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2013-11-20', '2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2013-11-20', '2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-11-20', '2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Lavelle', 'Rosamaria', 'Loan']\n last text, -- example: ['Vandervort', 'Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Vandervort', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2013-11-20', '2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2013-11-20', '2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2013-11-20', '2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nreason for encounter refers to encounters.REASONDESCRIPTION; on 11/20/2013 refers to encounters.DATE = '2013-11-20';\nTell me the reason for Lavelle Vandervort's encounter on 11/20/2013?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 728, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2013-11-20', '2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2013-11-20', '2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-11-20', '2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Lavelle', 'Rosamaria', 'Loan']\n last text, -- example: ['Vandervort', 'Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Vandervort', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2013-11-20', '2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2013-11-20', '2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2013-11-20', '2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nreason for encounter refers to encounters.REASONDESCRIPTION; on 11/20/2013 refers to encounters.DATE = '2013-11-20';\nTell me the reason for Lavelle Vandervort's encounter on 11/20/2013?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Viral Sinusitis (Disorder)', 'Sinusitis (Disorder)', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-06-13', '2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2008-06-13', '2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-06-13', '2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsocial security number refers to ssn; encountered viral sinusitis refers to encounters.REASONDESCRIPTION = 'Viral sinusitis (disorder)'; on 6/13/2008 refers to encounters.DATE = '2008-06-13';\nWhat is the social security number and address of the patient who encountered viral sinusitis symptoms on 6/13/2008?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 729, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Viral Sinusitis (Disorder)', 'Sinusitis (Disorder)', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-06-13', '2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2008-06-13', '2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-06-13', '2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsocial security number refers to ssn; encountered viral sinusitis refers to encounters.REASONDESCRIPTION = 'Viral sinusitis (disorder)'; on 6/13/2008 refers to encounters.DATE = '2008-06-13';\nWhat is the social security number and address of the patient who encountered viral sinusitis symptoms on 6/13/2008?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Major', 'Rosamaria', 'Loan']\n last text, -- example: [\"D'Amore\", 'Pfannerstill', 'Bashirian']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntypes of medications refers to medications.DESCRIPTION;\nHow many types of medication have been prescribed to Mr. Major D'Amore since his visit to the hospital?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 730, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Major', 'Rosamaria', 'Loan']\n last text, -- example: [\"D'Amore\", 'Pfannerstill', 'Bashirian']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntypes of medications refers to medications.DESCRIPTION;\nHow many types of medication have been prescribed to Mr. Major D'Amore since his visit to the hospital?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Hypertension', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Hypertension', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['M', 'S']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmale refers to gender = 'M'; diagnosed with hypertension refers to conditions.DESCRIPTION = 'Hypertension'; female refers to gender = 'F'; number of male patients with hypertension = count(patient WHERE gender = 'M' AND conditions.DESCRIPTION = 'Hypertension'); number of female patients with hypertension = count(patient WHERE gender = 'F' AND conditions.DESCRIPTION = 'Hypertension');\nHow many male patients are diagnosed with hypertension as compared to female patients?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 731, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Hypertension', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Hypertension', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['M', 'S']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmale refers to gender = 'M'; diagnosed with hypertension refers to conditions.DESCRIPTION = 'Hypertension'; female refers to gender = 'F'; number of male patients with hypertension = count(patient WHERE gender = 'M' AND conditions.DESCRIPTION = 'Hypertension'); number of female patients with hypertension = count(patient WHERE gender = 'F' AND conditions.DESCRIPTION = 'Hypertension');\nHow many male patients are diagnosed with hypertension as compared to female patients?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Total Cholesterol', 'Body Mass Index', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage body mass index = DIVIDE(SUM(observations.VALUE), COUNT(PATIENT) WHERE observations.DESCRIPTION = 'Body Mass Index'); body mass index refers to observations.DESCRIPTION = 'Body Mass Index'; higher total cholesterol refers to observations.DESCRIPTION = 'Total Cholesterol' and observations.VALUE > = 200;\nWhat is the average body mass index for patients with higher total cholesterol?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 732, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Total Cholesterol', 'Body Mass Index', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage body mass index = DIVIDE(SUM(observations.VALUE), COUNT(PATIENT) WHERE observations.DESCRIPTION = 'Body Mass Index'); body mass index refers to observations.DESCRIPTION = 'Body Mass Index'; higher total cholesterol refers to observations.DESCRIPTION = 'Total Cholesterol' and observations.VALUE > = 200;\nWhat is the average body mass index for patients with higher total cholesterol?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n prefix text, -- example: ['Mr.', 'Mrs.']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmost common condition refers to MAX(COUNT(conditions.DESCRIPTION)); age 60 and above refers to SUBTRACT(conditions.START, birthdate) > 60; percentage = MULTIPLY(DIVIDE(SUM(patients.patient WHERE MAX(COUNT(conditions.DESCRIPTION)) AND SUBTRACT(conditions.START, birthdate) > 60))), COUNT(patients.patient WHERE MAX(COUNT(conditions.DESCRIPTION)), 10);\nWhat is the percentage of the most common conditions for patients age 60 and above?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 733, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n prefix text, -- example: ['Mr.', 'Mrs.']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmost common condition refers to MAX(COUNT(conditions.DESCRIPTION)); age 60 and above refers to SUBTRACT(conditions.START, birthdate) > 60; percentage = MULTIPLY(DIVIDE(SUM(patients.patient WHERE MAX(COUNT(conditions.DESCRIPTION)) AND SUBTRACT(conditions.START, birthdate) > 60))), COUNT(patients.patient WHERE MAX(COUNT(conditions.DESCRIPTION)), 10);\nWhat is the percentage of the most common conditions for patients age 60 and above?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Walter', 'Rosamaria', 'Loan']\n last text, -- example: ['Bahringer', 'Walter', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nreason for visiting medical professionals refers to encounters.REASONDESCRIPTION;  in July 2009 refers to  substr(encounters.DATE, 1, 7) = '2009-07' ;\nName the reason Walter Bahringer visited medical professionals in July 2009.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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%'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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%'", "index": 734, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Walter', 'Rosamaria', 'Loan']\n last text, -- example: ['Bahringer', 'Walter', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nreason for visiting medical professionals refers to encounters.REASONDESCRIPTION;  in July 2009 refers to  substr(encounters.DATE, 1, 7) = '2009-07' ;\nName the reason Walter Bahringer visited medical professionals in July 2009.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Stacy', 'Rosamaria', 'Loan']\n last text, -- example: ['Morar', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Morar', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Emergency room admission', 'Emergency Room Admission', 'Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Drug Overdose', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Drug overdose', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nhow old = SUBTRACT(MIN(encounters.DATE), patients.birthdate); his first emergency room admission refers to MIN(encounters.DATE); drug overdose refers to encounters.REASONDESCRIPTION = 'Drug overdose' ;\nHow old was Mr. Stacy Morar at the time of his first emergency room admission due to a drug overdose?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 735, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Stacy', 'Rosamaria', 'Loan']\n last text, -- example: ['Morar', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Morar', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Emergency room admission', 'Emergency Room Admission', 'Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Drug Overdose', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Drug overdose', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nhow old = SUBTRACT(MIN(encounters.DATE), patients.birthdate); his first emergency room admission refers to MIN(encounters.DATE); drug overdose refers to encounters.REASONDESCRIPTION = 'Drug overdose' ;\nHow old was Mr. Stacy Morar at the time of his first emergency room admission due to a drug overdose?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Child attention deficit disorder', 'Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Child Attention Deficit Disorder', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Child attention deficit disorder', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Child attention deficit disorder', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Child attention deficit disorder', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Child attention deficit disorder', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndrug that was administered refers to medications.DESCRIPTION; child attention deficit disorder refers to medications.REASONDESCRIPTION = 'Child attention deficit disorder';\nWhat drug is administered more often to treat child attention deficit disorder?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DESCRIPTION FROM medications WHERE REASONDESCRIPTION = 'Child attention deficit disorder' GROUP BY DESCRIPTION ORDER BY COUNT(DESCRIPTION) DESC LIMIT 1", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT DESCRIPTION FROM medications WHERE REASONDESCRIPTION = 'Child attention deficit disorder' GROUP BY DESCRIPTION ORDER BY COUNT(DESCRIPTION) DESC LIMIT 1", "index": 736, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Child attention deficit disorder', 'Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Child Attention Deficit Disorder', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Child attention deficit disorder', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Child attention deficit disorder', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Child attention deficit disorder', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Child attention deficit disorder', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndrug that was administered refers to medications.DESCRIPTION; child attention deficit disorder refers to medications.REASONDESCRIPTION = 'Child attention deficit disorder';\nWhat drug is administered more often to treat child attention deficit disorder?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Transplant of lung (procedure)', 'Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull name = first, last; lung transplant refers to procedures.DESCRIPTION = 'Transplant of lung (procedure)';\nPlease include the full name of the patient who received a lung transplant.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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)'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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)'", "index": 737, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Transplant of lung (procedure)', 'Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull name = first, last; lung transplant refers to procedures.DESCRIPTION = 'Transplant of lung (procedure)';\nPlease include the full name of the patient who received a lung transplant.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n first text, -- example: ['Jacquelyn', 'Rosamaria', 'Loan']\n last text, -- example: ['Shanahan', 'Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Shanahan', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntime frame = SUBTRACT(JULIANDAY(careplans.STOP), JULIANDAY(careplans.START)); details of care plan refers to careplans.DESCRIPTION; most recent care plan refers to MIN(careplans.STAR);\nIndicate the time frame and details of the most recent care plan suggested to Jacquelyn Shanahan.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 738, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n first text, -- example: ['Jacquelyn', 'Rosamaria', 'Loan']\n last text, -- example: ['Shanahan', 'Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Shanahan', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntime frame = SUBTRACT(JULIANDAY(careplans.STOP), JULIANDAY(careplans.START)); details of care plan refers to careplans.DESCRIPTION; most recent care plan refers to MIN(careplans.STAR);\nIndicate the time frame and details of the most recent care plan suggested to Jacquelyn Shanahan.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n first text, -- example: ['Isadora', 'Rosamaria', 'Loan']\n last text, -- example: ['Moen', 'Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Moen', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nallergy period = SUBTRACT(allergies.START, allergies.STOP); what triggered the allergy refers to allergies.DESCRIPTION;\nIdentify the allergy period for Isadora Moen and what triggered it.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 739, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n first text, -- example: ['Isadora', 'Rosamaria', 'Loan']\n last text, -- example: ['Moen', 'Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Moen', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nallergy period = SUBTRACT(allergies.START, allergies.STOP); what triggered the allergy refers to allergies.DESCRIPTION;\nIdentify the allergy period for Isadora Moen and what triggered it.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n first text, -- example: ['Laronda', 'Rosamaria', 'Loan']\n last text, -- example: ['Bernier', 'Pfannerstill', 'Bashirian']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nhow old = SUBTRACT(MIN(encounters.DATE), patients.birthdate); most recent medical encounter refers to MIN(encounters.DATE);\nHow old was Mrs. Laronda Bernier at the time of her most recent medical encounter?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 740, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n first text, -- example: ['Laronda', 'Rosamaria', 'Loan']\n last text, -- example: ['Bernier', 'Pfannerstill', 'Bashirian']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nhow old = SUBTRACT(MIN(encounters.DATE), patients.birthdate); most recent medical encounter refers to MIN(encounters.DATE);\nHow old was Mrs. Laronda Bernier at the time of her most recent medical encounter?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Contact dermatitis', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Contact Dermatitis', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Contact dermatitis', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Contact dermatitis', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Contact dermatitis', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nin 2010 refers to substr(encounters.DATE, 1, 4) = '2010'; contact dermatitis refers to encounters.REASONDESCRIPTION = 'Contact dermatitis'; percentage = MULTIPLY(DIVIDE(COUNT(encounters.PATIENT WHERE gender = 'F'), count(encounters.PATIENT) WHERE encounters.REASONDESCRIPTION = 'Contact dermatitis'), 1.0) females refers to gender = 'F';\nAmong all patients who sought medical attention in 2010 due to contact dermatitis, identify the percentage of females.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 741, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Contact dermatitis', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Contact Dermatitis', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Contact dermatitis', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Contact dermatitis', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Contact dermatitis', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nin 2010 refers to substr(encounters.DATE, 1, 4) = '2010'; contact dermatitis refers to encounters.REASONDESCRIPTION = 'Contact dermatitis'; percentage = MULTIPLY(DIVIDE(COUNT(encounters.PATIENT WHERE gender = 'F'), count(encounters.PATIENT) WHERE encounters.REASONDESCRIPTION = 'Contact dermatitis'), 1.0) females refers to gender = 'F';\nAmong all patients who sought medical attention in 2010 due to contact dermatitis, identify the percentage of females.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Prenatal visit', 'Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Lorri', 'Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nbetween 2010 and 2017 refers to substr(encounters.DATE, 1, 4) between '2010' and '2017'; percentage = MULTIPLY(DIVIDE(COUNT(encounters.ID WHERE DESCRIPTION = 'Prenatal visit'), count(encounters.ID)), 1.0); prenatal visits refers to encounters.DESCRIPTION = 'Prenatal visit';\nHow many interactions did Lorri Simons have with medical professionals between 2010 and 2017? What percentage of encounters are attributed to prenatal visits?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 742, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Prenatal visit', 'Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Lorri', 'Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nbetween 2010 and 2017 refers to substr(encounters.DATE, 1, 4) between '2010' and '2017'; percentage = MULTIPLY(DIVIDE(COUNT(encounters.ID WHERE DESCRIPTION = 'Prenatal visit'), count(encounters.ID)), 1.0); prenatal visits refers to encounters.DESCRIPTION = 'Prenatal visit';\nHow many interactions did Lorri Simons have with medical professionals between 2010 and 2017? What percentage of encounters are attributed to prenatal visits?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n first text, -- example: ['Joe', 'Rosamaria', 'Loan']\n last text, -- example: ['Homenick', 'Pfannerstill', 'Bashirian']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndescription of medication refers to medications.DESCRIPTION;\nState description of medication taken by Joe Homenick.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 743, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n drivers text, -- example: ['S99992928', 'S99975961']\n first text, -- example: ['Joe', 'Rosamaria', 'Loan']\n last text, -- example: ['Homenick', 'Pfannerstill', 'Bashirian']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndescription of medication refers to medications.DESCRIPTION;\nState description of medication taken by Joe Homenick.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n prefix text, -- example: ['Mr.', 'Mrs.']\n maiden text, -- example: ['Adams', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstart date of the care plan refers to careplans.START;\nWhat is the start date of the care plan of the patient whose maiden name is Adams?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DISTINCT T1.START FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.maiden = 'Adams'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT DISTINCT T1.START FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.maiden = 'Adams'", "index": 744, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n prefix text, -- example: ['Mr.', 'Mrs.']\n maiden text, -- example: ['Adams', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstart date of the care plan refers to careplans.START;\nWhat is the start date of the care plan of the patient whose maiden name is Adams?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['hispanic', 'black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nHispanic patients refers to ethnicity = 'hispanic'; percentage = MULTIPLY(DIVIDE(COUNT(careplans.PATIENT WHERE ethnicity = 'hispanic'), COUNT(careplans.PATIENT)), 1.0); stopped their care plan in 2011 refers to substr(careplans.stop, 1, 4) = '2011';\nWhat is the percentage of Hispanic patients who stopped their care plan in 2011?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 745, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['hispanic', 'black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nHispanic patients refers to ethnicity = 'hispanic'; percentage = MULTIPLY(DIVIDE(COUNT(careplans.PATIENT WHERE ethnicity = 'hispanic'), COUNT(careplans.PATIENT)), 1.0); stopped their care plan in 2011 refers to substr(careplans.stop, 1, 4) = '2011';\nWhat is the percentage of Hispanic patients who stopped their care plan in 2011?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Angelo', 'Rosamaria', 'Loan']\n last text, -- example: ['Buckridge', 'Pfannerstill', 'Bashirian']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndescription of the reason of the care plan refers to careplans.REASONDESCRIPTION;\nState the description of the reason why Angelo Buckridge needs the care plan.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 746, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Angelo', 'Rosamaria', 'Loan']\n last text, -- example: ['Buckridge', 'Pfannerstill', 'Bashirian']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndescription of the reason of the care plan refers to careplans.REASONDESCRIPTION;\nState the description of the reason why Angelo Buckridge needs the care plan.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n marital text, -- example: ['S', 'M']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pembroke MA US', 'Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmedical encounter ids careplans.ID; born in Pembroke MA US refers to birthplace = 'Pembroke MA US';\nWhat are the medical encounter ids of patients who were born in Pembroke MA US?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DISTINCT T1.ENCOUNTER FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.birthplace = 'Pembroke MA US'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT DISTINCT T1.ENCOUNTER FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.birthplace = 'Pembroke MA US'", "index": 747, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n marital text, -- example: ['S', 'M']\n ethnicity text, -- example: ['dominican', 'american']\n birthplace text, -- example: ['Pembroke MA US', 'Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmedical encounter ids careplans.ID; born in Pembroke MA US refers to birthplace = 'Pembroke MA US';\nWhat are the medical encounter ids of patients who were born in Pembroke MA US?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['White', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['white', 'black']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nwhite refers to race = 'white'; reason code of 10509002 refers to careplans.REASONCODE = '10509002';\nHow many white patients have the reason code of 10509002?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 748, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['White', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['white', 'black']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nwhite refers to race = 'white'; reason code of 10509002 refers to careplans.REASONCODE = '10509002';\nHow many white patients have the reason code of 10509002?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n marital text, -- example: ['S', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstop date of the care plan refers to careplans.STOP; dead patients refers to deathdate is not null;\nList out the stop date of the care plan of dead patients.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 749, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n marital text, -- example: ['S', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstop date of the care plan refers to careplans.STOP; dead patients refers to deathdate is not null;\nList out the stop date of the care plan of dead patients.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nblack refers to race = 'black'; stopped their care plan in 2017 refers to substr(careplans.STOP, 1, 4) = '2017';\nHow many black patients stopped their care plan in 2017?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 750, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nblack refers to race = 'black'; stopped their care plan in 2017 refers to substr(careplans.STOP, 1, 4) = '2017';\nHow many black patients stopped their care plan in 2017?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Allergy To Nut', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to nut', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull names = first, last; nut allergy refers to allergies.DESCRIPTION = 'Allergy to nut';\nList the full names of patients with nut allergy.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 751, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Allergy To Nut', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to nut', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull names = first, last; nut allergy refers to allergies.DESCRIPTION = 'Allergy to nut';\nList the full names of patients with nut allergy.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Wilmer', 'Rosamaria', 'Loan']\n last text, -- example: ['Koepp', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Koepp', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nDescribe the condition of patient Wilmer Koepp.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 752, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Wilmer', 'Rosamaria', 'Loan']\n last text, -- example: ['Koepp', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Koepp', 'Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nDescribe the condition of patient Wilmer Koepp.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Viral Sinusitis (Disorder)', 'Sinusitis (Disorder)', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nviral sinusitis condition refers to conditions.DESCRIPTION = 'Viral sinusitis (disorder)'; gender that is most affected refers to MAX(COUNT(gender WHERE conditions.DESCRIPTION = 'Viral sinusitis (disorder)'));\nAmong the patients with viral sinusitis condition, which patient's gender is most affected? Provide the number for each respectively.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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)'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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)'", "index": 753, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Viral Sinusitis (Disorder)', 'Sinusitis (Disorder)', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Viral sinusitis (disorder)', 'Sinusitis (disorder)', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nviral sinusitis condition refers to conditions.DESCRIPTION = 'Viral sinusitis (disorder)'; gender that is most affected refers to MAX(COUNT(gender WHERE conditions.DESCRIPTION = 'Viral sinusitis (disorder)'));\nAmong the patients with viral sinusitis condition, which patient's gender is most affected? Provide the number for each respectively.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Stroke', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Stroke', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Stroke', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Stroke', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Stroke', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['White', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['white', 'black']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nwhite refers to race = 'white'; birth year is 1935 refers to substr(birthdate, 1, 4) = '1935'; stroke refers to conditions.DESCRIPTION = 'Stroke';\nHow many white patients whose birth year is 1935 have a stroke?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 754, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Stroke', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Stroke', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Stroke', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Stroke', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Stroke', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['White', 'Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['white', 'black']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nwhite refers to race = 'white'; birth year is 1935 refers to substr(birthdate, 1, 4) = '1935'; stroke refers to conditions.DESCRIPTION = 'Stroke';\nHow many white patients whose birth year is 1935 have a stroke?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\npatient ids refers to patients.patient; disease with the most occurrence refers to MAX(all_prevalences.OCCURENCES);\nList the patient ids whose disease has the most occurrences.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 755, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n passport text, -- example: ['FALSE', 'X98167138X']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\npatient ids refers to patients.patient; disease with the most occurrence refers to MAX(all_prevalences.OCCURENCES);\nList the patient ids whose disease has the most occurrences.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Cystitis', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Cystitis', 'Acute bronchitis (disorder)']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Cystitis', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull names = first, last; condition described as cystitis refers to conditions.DESCRIPTION = ''Cystitis';\nList all the full names of patients with a condition described as cystitis.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DISTINCT T1.first, T1.last FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.patient WHERE T2.DESCRIPTION = 'Cystitis'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT DISTINCT T1.first, T1.last FROM patients AS T1 INNER JOIN conditions AS T2 ON T1.patient = T2.patient WHERE T2.DESCRIPTION = 'Cystitis'", "index": 756, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Cystitis', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Cystitis', 'Acute bronchitis (disorder)']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Cystitis', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull names = first, last; condition described as cystitis refers to conditions.DESCRIPTION = ''Cystitis';\nList all the full names of patients with a condition described as cystitis.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n gender text, -- example: ['M', 'F']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmale refers to gender = 'M'; immune to quadrivalent HPV refers to immunizations.DESCRIPTION = 'HPV quadrivalent';\nHow many male patients have been described as immune to quadrivalent HPV?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 757, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n gender text, -- example: ['M', 'F']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmale refers to gender = 'M'; immune to quadrivalent HPV refers to immunizations.DESCRIPTION = 'HPV quadrivalent';\nHow many male patients have been described as immune to quadrivalent HPV?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n drivers text, -- example: ['S99992928', 'S99975961']\n first text, -- example: ['Walter', 'Rosamaria', 'Loan']\n last text, -- example: ['Bahringer', 'Walter', 'Pfannerstill', 'Bashirian']\n marital text, -- example: ['S', 'M']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstart date of the care plan refers to careplans.START;\nIndicate the start date of patient Walter Bahringer's care plan.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 758, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n drivers text, -- example: ['S99992928', 'S99975961']\n first text, -- example: ['Walter', 'Rosamaria', 'Loan']\n last text, -- example: ['Bahringer', 'Walter', 'Pfannerstill', 'Bashirian']\n marital text, -- example: ['S', 'M']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstart date of the care plan refers to careplans.START;\nIndicate the start date of patient Walter Bahringer's care plan.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Asthma', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to peanuts', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Asthma', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Allergy To Peanuts', 'Asthma', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Asthma', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Asthma', 'Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Asthma', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nallergic to peanuts refers to allergies.DESCRIPTION = 'Allergy to peanuts'; asthma refers to conditions.DESCRIPTION = 'Asthma';\nHow many patients who are allergic to peanuts have asthma?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 759, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Asthma', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to peanuts', 'Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Asthma', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Allergy To Peanuts', 'Asthma', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Asthma', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Asthma', 'Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Asthma', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nallergic to peanuts refers to allergies.DESCRIPTION = 'Allergy to peanuts'; asthma refers to conditions.DESCRIPTION = 'Asthma';\nHow many patients who are allergic to peanuts have asthma?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Drug overdose', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Drug Overdose', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\n44-year-old = DIVIDE(SUBTRACT(julianday(conditions.START), julianday(patients.birthdate)), 365, 0) = 44;\nWho is the 44-year-old patient diagnosed with drug overdose?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 760, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Drug overdose', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Drug overdose', 'Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Drug Overdose', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n PRIMARY KEY (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\n44-year-old = DIVIDE(SUBTRACT(julianday(conditions.START), julianday(patients.birthdate)), 365, 0) = 44;\nWho is the 44-year-old patient diagnosed with drug overdose?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Systolic Blood Pressure', 'Diastolic Blood Pressure', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsocial security number refers to ssn; highest systolic blood pressure refers to MAX(observations.VALUE WHERE observations.DESCRIPTION = 'Systolic Blood Pressure');\nProvide the social security number of the patient with the highest systolic blood pressure.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 761, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Systolic Blood Pressure', 'Diastolic Blood Pressure', 'Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsocial security number refers to ssn; highest systolic blood pressure refers to MAX(observations.VALUE WHERE observations.DESCRIPTION = 'Systolic Blood Pressure');\nProvide the social security number of the patient with the highest systolic blood pressure.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-15-3685', '999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsocial security number refers to ssn; ssn = '999-15-3685';\nWhat is the care plan for the patient with social security number 999-15-3685?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DISTINCT T1.DESCRIPTION FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.ssn = '999-15-3685'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "SELECT DISTINCT T1.DESCRIPTION FROM careplans AS T1 INNER JOIN patients AS T2 ON T1.PATIENT = T2.patient WHERE T2.ssn = '999-15-3685'", "index": 762, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-15-3685', '999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n marital text, -- example: ['S', 'M']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['F', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsocial security number refers to ssn; ssn = '999-15-3685';\nWhat is the care plan for the patient with social security number 999-15-3685?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Hypertension', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['M', 'S']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['M', 'F']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Hypertension', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage age = AVG(DIVIDE(SUBTRACT(deathdate is null WHERE (julianday(substr(datetime('now'), 1, 10)))), julianday(patients.birthdate)), 365); male refers to gender = 'M'; hypertension refers to conditions.DESCRIPTION = 'Hypertension'\nCalculate the average age of the male patients that have hypertension.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 763, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n ORGANIZATION text, -- example: ['temp organization']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Hypertension', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE PERCENTAGE` real, -- example: [86.8, 48.7]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['M', 'S']\n race text, -- example: ['black', 'white']\n ethnicity text, -- example: ['dominican', 'american']\n gender text, -- example: ['M', 'F']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE real, -- example: [53950000.0, 304510005.0]\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Hypertension', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage age = AVG(DIVIDE(SUBTRACT(deathdate is null WHERE (julianday(substr(datetime('now'), 1, 10)))), julianday(patients.birthdate)), 365); male refers to gender = 'M'; hypertension refers to conditions.DESCRIPTION = 'Hypertension'\nCalculate the average age of the male patients that have hypertension.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Weight', 'Body Height']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['kg', 'cm']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nbody weight of 61.97 kg refers to observations.DESCRIPTION = 'Body Weight' AND observations.VALUE = 61.97; observations.UNITS = 'kg'\nWho is the patient with a body weight of 61.97 kg?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 764, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE procedures (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION COUNT` integer, -- example: [1000]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Body Weight', 'Body Height']\n `VALUE` real, -- example: [166.03, 54.42]\n UNITS text, -- example: ['kg', 'cm']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nbody weight of 61.97 kg refers to observations.DESCRIPTION = 'Body Weight' AND observations.VALUE = 61.97; observations.UNITS = 'kg'\nWho is the patient with a body weight of 61.97 kg?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['M', 'S']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['M', 'F']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Penicillin V Potassium 250 Mg', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Potassium', 'Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmale patients refers to gender = 'M'; Penicillin V Potassium 250 MG refers to medications.DESCRIPTION = 'Penicillin V Potassium 250 MG';\nAmong the male patients, list down 5 birth dates of patients taking the medication \"Penicillin V Potassium 250 MG\".\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 765, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n birthdate date, -- example: ['1929-04-08', '2016-12-15']\n deathdate date, -- example: ['2029-11-11', '2020-02-19']\n drivers text, -- example: ['S99992928', 'S99975961']\n prefix text, -- example: ['Mr.', 'Mrs.']\n first text, -- example: ['Rosamaria', 'Loan']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['M', 'S']\n race text, -- example: ['black', 'white']\n gender text, -- example: ['M', 'F']\n address text, -- example: ['18797 Karson Burgs Suite 444 Palmer Town', '301 Eula Radial Suite 298 Brockton MA 02']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Penicillin V Potassium 250 Mg', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n `POPULATION TYPE` text, -- example: ['LIVING']\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n DESCRIPTION text, -- example: ['Potassium', 'Body Height', 'Body Weight']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n BILLABLEPERIOD date, -- example: ['2008-03-11', '2009-01-11']\n DIAGNOSIS text,\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nmale patients refers to gender = 'M'; Penicillin V Potassium 250 MG refers to medications.DESCRIPTION = 'Penicillin V Potassium 250 MG';\nAmong the male patients, list down 5 birth dates of patients taking the medication \"Penicillin V Potassium 250 MG\".\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n ethnicity text, -- example: ['irish', 'dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull name = first, last; Irish refers to ethnicity = 'irish'; prevalent diseases that have an occurrence greater than the 96% of the average occurrences of all conditions = OCCURRENCES > (AVG(MULTIPLY(all_prevalences.OCCURRENCES, 0.96)));\nList 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.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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", "index": 766, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONDESCRIPTION text, -- example: ['Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DIAGNOSIS text,\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n first text, -- example: ['Rosamaria', 'Loan']\n last text, -- example: ['Pfannerstill', 'Bashirian']\n maiden text, -- example: ['Schuster', 'Schaden']\n ethnicity text, -- example: ['irish', 'dominican', 'american']\n gender text, -- example: ['F', 'M']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n UNITS text, -- example: ['cm', 'kg']\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n ID text, -- example: ['e031962d-d13d-4ede-a449-040417d5e4fb', '26b879b7-0066-4bd6-b59c-099909720155']\n `START` date, -- example: ['2009-01-11', '2010-10-16']\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n `DATE` date, -- example: ['2008-03-11', '2009-01-11']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONCODE integer, -- example: [10509002, 38822007]\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull name = first, last; Irish refers to ethnicity = 'irish'; prevalent diseases that have an occurrence greater than the 96% of the average occurrences of all conditions = OCCURRENCES > (AVG(MULTIPLY(all_prevalences.OCCURRENCES, 0.96)));\nList 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.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Diabetes', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Diabetes', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Rosamaria', 'Loan']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Diabetes', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Diabetes', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndifference = SUBTRACT(patients.patient WHERE marital = 'M'), COUNT(patients.patient WHERE marital = 'S') WHERE conditions.DESCRIPTION = 'Diabetes'); married patients refers to marital = 'M'; single patients refers to marital = 'S'; diabetes refers to conditions.DESCRIPTION = 'Diabetes';\nWhat is the difference between the number of married patients and the number of single patients with diabetes?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "synthea.sqlite", "gt_sql": "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'", "index": 767, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE allergies (\n `START` text, -- example: ['3/11/95', '6/15/58']\n STOP text, -- example: ['12/22/14', '4/21/10']\n PATIENT text, -- example: ['00341a88-1cc1-4b39-b0f9-05b0531991a0', '01347a8e-3a92-4f1e-99c9-5d6df0db2331']\n ENCOUNTER text, -- example: ['ddc8a625-07e6-4a02-a616-e0ce07b5f305', '84714823-ee2b-42ba-b79b-6043270cfdc7']\n CODE integer, -- example: [232347008, 300916003]\n DESCRIPTION text, -- example: ['Allergy to dairy product', 'Allergy to tree pollen']\n PRIMARY KEY (PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_allergies_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_allergies_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE procedures (\n `DATE` date, -- example: ['2013-02-09', '2013-10-19']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', '96b24072-e1fe-49cd-a22a-6dfb92c3994c']\n ENCOUNTER text, -- example: ['6f2e3935-b203-493e-a9c0-f23e847b9798', 'da4fd626-e74e-4930-91be-7fb3da7ea098']\n CODE integer, -- example: [23426006, 252160004]\n DESCRIPTION text, -- example: ['Measurement of respiratory function (pro', 'Standard pregnancy test']\n REASONCODE integer, -- example: [10509002, 72892002]\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Normal pregnancy']\n CONSTRAINT fk_procedures_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_procedures_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE careplans (\n STOP date, -- example: ['2009-04-07', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n DESCRIPTION text, -- example: ['Respiratory therapy', 'Recommendation to avoid exercise']\n REASONCODE integer, -- example: [10509002, 38822007]\n REASONDESCRIPTION text, -- example: ['Diabetes', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_careplans_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_careplans_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE medications (\n `START` date, -- example: ['1918-04-17', '1919-06-28']\n STOP date, -- example: ['2008-06-04', '2009-01-21']\n PATIENT text, -- example: ['ce11bcba-c83c-43ae-802d-b20ee8715afe', 'a9c61b1f-3ad5-47e0-9aae-1613640a8187']\n ENCOUNTER text, -- example: ['6334071d-e6b0-42c1-a082-2a08e123de4e', '23ab74d3-044b-465b-ad85-394acfda0ef7']\n CODE integer, -- example: [834060, 745679]\n DESCRIPTION text, -- example: ['Penicillin V Potassium 250 MG', 'NuvaRing 0.12/0.015 MG per 24HR 21 Day V']\n REASONCODE integer, -- example: [43878008, 10509002]\n REASONDESCRIPTION text, -- example: ['Diabetes', 'Streptococcal sore throat (disorder)', 'Acute bronchitis (disorder)']\n PRIMARY KEY (`START`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_medications_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_medications_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE encounters (\n ID text, -- example: ['000c20ea-5c3d-43a3-9608-bd37c22f13c8', '0013c51f-c315-4112-ad5e-466b604a05ed']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n CODE integer, -- example: [185349003, 185345009]\n DESCRIPTION text, -- example: ['Outpatient Encounter', 'Encounter for symptom']\n REASONDESCRIPTION text, -- example: ['Acute bronchitis (disorder)', 'Cystitis']\n PRIMARY KEY (ID),\n CONSTRAINT fk_encounters_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient)\n);\n\nCREATE TABLE patients (\n patient text, -- example: ['00269bb7-e3ab-43a9-9cdf-cdf9b6e3b2b3', '00341a88-1cc1-4b39-b0f9-05b0531991a0']\n ssn text, -- social security number, example: ['999-78-5976', '999-59-9186']\n passport text, -- example: ['FALSE', 'X98167138X']\n first text, -- example: ['Rosamaria', 'Loan']\n suffix text, -- example: ['PhD', 'JD']\n maiden text, -- example: ['Schuster', 'Schaden']\n marital text, -- example: ['S', 'M']\n birthplace text, -- example: ['Pittsfield MA US', 'Medford MA US']\n PRIMARY KEY (patient)\n);\n\nCREATE TABLE all_prevalences (\n ITEM text, -- example: ['Diabetes', '0.3 Ml Epinephrine 0.5 Mg/Ml Auto Inject', '0.65 Ml Depo Subq Provera 160 Mg/Ml Pref']\n OCCURRENCES integer, -- example: [868, 487]\n `POPULATION COUNT` integer, -- example: [1000]\n `PREVALENCE RATE` real, -- example: [0.868, 0.487]\n PRIMARY KEY (ITEM)\n);\n\nCREATE TABLE observations (\n `DATE` date, -- example: ['2008-03-11', '2009-04-07']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['5114a5b4-64b8-47b2-82a6-0ce24aae0943', 'bdb926b8-5b6d-4366-bbe9-76fe3f3fbc4f']\n CODE text, -- example: ['8302-2', '29463-7']\n DESCRIPTION text, -- example: ['Body Height', 'Body Weight']\n `VALUE` real, -- example: [166.03, 54.42]\n CONSTRAINT fk_observations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_observations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE immunizations (\n `DATE` date, -- example: ['2007-11-02', '2007-11-03']\n PATIENT text, -- example: ['70cbc79e-dd9d-4e3b-8158-a92d85951f94', '87828e93-e09b-435b-be8e-657361f1c68a']\n ENCOUNTER text, -- example: ['898ab2de-8a71-4fb3-b239-b768b915284a', 'fc8e3271-cc7c-4169-8c99-d46635a86478']\n CODE integer, -- example: [8, 62]\n DESCRIPTION text, -- example: ['Influenza seasonal injectable preserv', 'Td (adult) preservative free']\n PRIMARY KEY (`DATE`, PATIENT, ENCOUNTER, CODE),\n CONSTRAINT fk_immunizations_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_immunizations_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID)\n);\n\nCREATE TABLE conditions (\n `START` date, -- example: ['2009-01-08', '2010-10-16']\n STOP date, -- example: ['2009-01-21', '2010-10-23']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['4d451e22-a354-40c9-8b33-b6126158666d', 'bed7ecff-b41c-422b-beac-ea00c8b02837']\n CODE integer, -- example: [10509002, 38822007]\n DESCRIPTION text, -- example: ['Diabetes', 'Acute bronchitis (disorder)', 'Cystitis']\n CONSTRAINT fk_conditions_patient FOREIGN KEY (PATIENT) REFERENCES patients (patient),\n CONSTRAINT fk_conditions_encounter FOREIGN KEY (ENCOUNTER) REFERENCES encounters (ID),\n CONSTRAINT fk_conditions_description FOREIGN KEY (DESCRIPTION) REFERENCES all_prevalences (ITEM)\n);\n\nCREATE TABLE claims (\n ID text, -- example: ['0004caaf-fd7a-4f64-bda6-dce5ebd1196c', '000acf3a-fcac-4cab-ac41-0153802bfd8c']\n PATIENT text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n ENCOUNTER text, -- example: ['71949668-1c2e-43ae-ab0a-64654608defb', 'c2caaace-9119-4b2d-a2c3-4040f5a9cf32']\n TOTAL integer, -- example: [100]\n PRIMARY KEY (ID)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ndifference = SUBTRACT(patients.patient WHERE marital = 'M'), COUNT(patients.patient WHERE marital = 'S') WHERE conditions.DESCRIPTION = 'Diabetes'); married patients refers to marital = 'M'; single patients refers to marital = 'S'; diabetes refers to conditions.DESCRIPTION = 'Diabetes';\nWhat is the difference between the number of married patients and the number of single patients with diabetes?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nList the country and how many customers are there.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT country, COUNT(customerNumber) FROM customers GROUP BY country", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT country, COUNT(customerNumber) FROM customers GROUP BY country", "index": 768, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nList the country and how many customers are there.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n firstName text, -- example: ['Diane', 'Mary']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Mini Gifts Distributors Ltd.', 'Rovelli Gifts', 'Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Rovelli', 'Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-09', '2003-01-06']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nMini Gifts Distributors Ltd. Is the customer name; shippedDate between '2003-01-01' and '2003-12-31'; total price = MULTIPLY(quantityOrdered, priceEach);\nWhat was the total price of the products shipped to Rovelli Gifts Distributors Ltd. between 1/1/2003 and 12/31/2003?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "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'", "index": 769, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n firstName text, -- example: ['Diane', 'Mary']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Mini Gifts Distributors Ltd.', 'Rovelli Gifts', 'Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Rovelli', 'Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-09', '2003-01-06']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nMini Gifts Distributors Ltd. Is the customer name; shippedDate between '2003-01-01' and '2003-12-31'; total price = MULTIPLY(quantityOrdered, priceEach);\nWhat was the total price of the products shipped to Rovelli Gifts Distributors Ltd. between 1/1/2003 and 12/31/2003?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['Sales Rep', 'President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['Sydney', 'San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsales agent and sales representative are synonyms; Sydney is a city;\nHow many employees are there in Sydney?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(employeeNumber) FROM employees WHERE officeCode = ( SELECT officeCode FROM offices WHERE city = 'Sydney' )", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT COUNT(employeeNumber) FROM employees WHERE officeCode = ( SELECT officeCode FROM offices WHERE city = 'Sydney' )", "index": 770, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['Sales Rep', 'President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['Sydney', 'San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsales agent and sales representative are synonyms; Sydney is a city;\nHow many employees are there in Sydney?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Euro+ Shopping Channel', 'Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nEuro+ Shopping Channel is a customer name; year(paymentDate) = '2004';\nHow many checks were issued by Euro+ Shopping Channel in the year 2004?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "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'", "index": 771, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Euro+ Shopping Channel', 'Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nEuro+ Shopping Channel is a customer name; year(paymentDate) = '2004';\nHow many checks were issued by Euro+ Shopping Channel in the year 2004?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n productScale text, -- example: ['1:18', '1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nclassic car is a product line; most ordered product refers to MAX(quantityOrdered);\nOf all the classic cars, with a product scale of 1:18, which product is the most ordered product by customers?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "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", "index": 772, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n productScale text, -- example: ['1:18', '1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nclassic car is a product line; most ordered product refers to MAX(quantityOrdered);\nOf all the classic cars, with a product scale of 1:18, which product is the most ordered product by customers?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ncreditLimit < = 100000; total payment amount refers to amount; highest total payment amount refers to MAX(amount); year(paymentDate) = '2004';\nHow 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?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "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", "index": 773, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ncreditLimit < = 100000; total payment amount refers to amount; highest total payment amount refers to MAX(amount); year(paymentDate) = '2004';\nHow 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?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Cancelled', 'Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntotal price = MULTIPLY(quantityOrdered, priceEach) > 4000; cancelled orders refer to status = 'Cancelled';\nHow many different orders with a total price greater than 4000 are cancelled?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "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'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "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'", "index": 774, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Cancelled', 'Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntotal price = MULTIPLY(quantityOrdered, priceEach) > 4000; cancelled orders refer to status = 'Cancelled';\nHow many different orders with a total price greater than 4000 are cancelled?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Cancelled', 'Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntotal value = SUM(MULTIPLY(quantityOrdered, priceEach)); cancelled orders refers to status = 'Cancelled';\nWhat is the total value of cancelled orders?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT SUM(T1.quantityOrdered * T1.priceEach) FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber WHERE T2.status = 'Cancelled'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT SUM(T1.quantityOrdered * T1.priceEach) FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber WHERE T2.status = 'Cancelled'", "index": 775, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Cancelled', 'Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntotal value = SUM(MULTIPLY(quantityOrdered, priceEach)); cancelled orders refers to status = 'Cancelled';\nWhat is the total value of cancelled orders?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n state text, -- example: ['NV', 'Victoria']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nexpected profits greater than 100 = (SUBTRACT(msrp, buyPrice))>100;\nHow many orders which expected profits greater than 100?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(T1.productCode) FROM orderdetails AS T1 INNER JOIN products AS T2 ON T1.productCode = T2.productCode WHERE T2.MSRP - T2.buyPrice > 100", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT COUNT(T1.productCode) FROM orderdetails AS T1 INNER JOIN products AS T2 ON T1.productCode = T2.productCode WHERE T2.MSRP - T2.buyPrice > 100", "index": 776, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n state text, -- example: ['NV', 'Victoria']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nexpected profits greater than 100 = (SUBTRACT(msrp, buyPrice))>100;\nHow many orders which expected profits greater than 100?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n state text, -- example: ['NV', 'Victoria']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n buyPrice real, -- example: [48.81, 98.58]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['Sales Rep', 'President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsales representative refers to jobTitle = 'Sales Rep';\nHow many sales representatives who have office code is 1?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT COUNT(officeCode) FROM employees WHERE jobTitle = 'Sales Rep' AND officeCode = 1", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT COUNT(officeCode) FROM employees WHERE jobTitle = 'Sales Rep' AND officeCode = 1", "index": 777, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n state text, -- example: ['NV', 'Victoria']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n buyPrice real, -- example: [48.81, 98.58]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['Sales Rep', 'President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nsales representative refers to jobTitle = 'Sales Rep';\nHow many sales representatives who have office code is 1?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n firstName text, -- example: ['Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\namount > 50000;\nPlease list different customer names with the payment amount of over 50,000.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT DISTINCT T2.customerName FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.amount > 50000", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT DISTINCT T2.customerName FROM payments AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.amount > 50000", "index": 778, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n firstName text, -- example: ['Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\namount > 50000;\nPlease list different customer names with the payment amount of over 50,000.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n state text, -- example: ['NV', 'Victoria']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntotal payment refers to SUM(amount); no credit limit refers to creditLimit = 0; year(paymentDate) = '2003';\nWhat are the total payments of customers with no credit limit in 2003?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT SUM(amount) FROM payments WHERE STRFTIME('%Y', paymentDate) = '2003' AND customerNumber IN ( SELECT customerNumber FROM customers WHERE creditLimit = 0 )", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT SUM(amount) FROM payments WHERE STRFTIME('%Y', paymentDate) = '2003' AND customerNumber IN ( SELECT customerNumber FROM customers WHERE creditLimit = 0 )", "index": 779, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n state text, -- example: ['NV', 'Victoria']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntotal payment refers to SUM(amount); no credit limit refers to creditLimit = 0; year(paymentDate) = '2003';\nWhat are the total payments of customers with no credit limit in 2003?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n status text, -- example: ['Cancelled', 'Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ncancelled order refers to status = 'Cancelled';\nPlease list the name and phone number of the customer whose order was cancelled.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T2.customerName, T2.phone FROM orders AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.status = 'Cancelled'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T2.customerName, T2.phone FROM orders AS T1 INNER JOIN customers AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.status = 'Cancelled'", "index": 780, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n status text, -- example: ['Cancelled', 'Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ncancelled order refers to status = 'Cancelled';\nPlease list the name and phone number of the customer whose order was cancelled.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['Germany', 'France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage total price = DIVIDE(MULTIPLY(quantityOrdered, priceEach)), COUNT(orderNumber)); German is a nationality of country = 'Germany'; shipped orders refers to status = 'Shipped';\nPlease calculate the average total price of shipped orders from German customers.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT SUM(T3.quantityOrdered * T3.priceEach) / COUNT(T2.orderNumber) 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 T2.status = 'Shipped' AND T1.country = 'Germany'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT SUM(T3.quantityOrdered * T3.priceEach) / COUNT(T2.orderNumber) 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 T2.status = 'Shipped' AND T1.country = 'Germany'", "index": 781, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['Germany', 'France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage total price = DIVIDE(MULTIPLY(quantityOrdered, priceEach)), COUNT(orderNumber)); German is a nationality of country = 'Germany'; shipped orders refers to status = 'Shipped';\nPlease calculate the average total price of shipped orders from German customers.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Murphy', 'Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['San Francisco', 'Nantes', 'Las Vegas']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstaff of refers to reportsTO; San Francisco is a city;\nState the email of those who are staff of Murphy Diane whose number is 1002 and living in San Francisco\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.email FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T1.reportsTo = 1002 AND T2.city = 'San Francisco'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T1.email FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T1.reportsTo = 1002 AND T2.city = 'San Francisco'", "index": 782, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Murphy', 'Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['San Francisco', 'Nantes', 'Las Vegas']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nstaff of refers to reportsTO; San Francisco is a city;\nState the email of those who are staff of Murphy Diane whose number is 1002 and living in San Francisco\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['MA', 'NV', 'Victoria']\n country text, -- example: ['USA', 'France']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['MA', 'CA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ncode of employee refers to employeeNumber; United States of America refers to country = 'USA';\nDetermine the email and Code of employee who are working at United State, state MA\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.email, T1.employeeNumber FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.state = 'MA' AND T2.country = 'USA'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T1.email, T1.employeeNumber FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.state = 'MA' AND T2.country = 'USA'", "index": 783, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['MA', 'NV', 'Victoria']\n country text, -- example: ['USA', 'France']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['MA', 'CA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ncode of employee refers to employeeNumber; United States of America refers to country = 'USA';\nDetermine the email and Code of employee who are working at United State, state MA\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\namount of payment refers to amount;\nList out 3 customer numbers who have highest amount payment\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT customerNumber FROM payments ORDER BY amount DESC LIMIT 3", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT customerNumber FROM payments ORDER BY amount DESC LIMIT 3", "index": 784, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\namount of payment refers to amount;\nList out 3 customer numbers who have highest amount payment\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n state text, -- example: ['CA', 'NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['USA', 'France']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nUnited States of America refers to country = 'USA'; code of employee refers to employeeNumber;\nDetermine the email and Code of employee who are working at United State, state CA\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.email, T1.employeeNumber FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.country = 'USA' AND T2.state = 'CA' GROUP BY T1.email, T1.officeCode", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T1.email, T1.employeeNumber FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.country = 'USA' AND T2.state = 'CA' GROUP BY T1.email, T1.officeCode", "index": 785, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n state text, -- example: ['CA', 'NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['USA', 'France']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nUnited States of America refers to country = 'USA'; code of employee refers to employeeNumber;\nDetermine the email and Code of employee who are working at United State, state CA\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['Boston', 'San Francisco']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Boston', 'Nantes', 'Las Vegas']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull name = contactFirstName, contactLastName; Boston is a city;\nList out full name of employees who are working in Boston?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.firstName, T1.lastName FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.city = 'Boston'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T1.firstName, T1.lastName FROM employees AS T1 INNER JOIN offices AS T2 ON T1.officeCode = T2.officeCode WHERE T2.city = 'Boston'", "index": 786, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['Boston', 'San Francisco']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Boston', 'Nantes', 'Las Vegas']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull name = contactFirstName, contactLastName; Boston is a city;\nList out full name of employees who are working in Boston?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\npayment refers to amount; full name = firstName+lastName; supervisor refers to reportsTO; 'reportsTO' is the leader of the 'employeeNumber';\nWho is the sales agent of the customer who has made the highest payment? Include the full names of employee and his/her supervisor.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.firstName, T1.lastName, T1.reportsTo FROM employees AS T1 INNER JOIN customers AS T2 ON T1.employeeNumber = T2.salesRepEmployeeNumber INNER JOIN payments AS T3 ON T2.customerNumber = T3.customerNumber ORDER BY T3.amount DESC LIMIT 1", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T1.firstName, T1.lastName, T1.reportsTo FROM employees AS T1 INNER JOIN customers AS T2 ON T1.employeeNumber = T2.salesRepEmployeeNumber INNER JOIN payments AS T3 ON T2.customerNumber = T3.customerNumber ORDER BY T3.amount DESC LIMIT 1", "index": 787, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\npayment refers to amount; full name = firstName+lastName; supervisor refers to reportsTO; 'reportsTO' is the leader of the 'employeeNumber';\nWho is the sales agent of the customer who has made the highest payment? Include the full names of employee and his/her supervisor.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['Sales Rep', 'President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['Boston', 'San Francisco']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n city text, -- example: ['Boston', 'Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nBoston is a city; amount of order = MULTIPLY(quantityOrdered, priceEach);\nWhat is the highest amount of order made by the sales representative in Boston? Please give the name of the product and amount.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T2.productName, T1.quantityOrdered * T1.priceEach FROM orderdetails AS T1 INNER JOIN products AS T2 ON T1.productCode = T2.productCode INNER JOIN orders AS T3 ON T1.orderNumber = T3.orderNumber INNER JOIN customers AS T4 ON T3.customerNumber = T4.customerNumber WHERE T4.city = 'Boston' AND T4.salesRepEmployeeNumber IN ( SELECT employeeNumber FROM employees WHERE jobTitle = 'Sales Rep' ) ORDER BY T1.quantityOrdered DESC LIMIT 1", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T2.productName, T1.quantityOrdered * T1.priceEach FROM orderdetails AS T1 INNER JOIN products AS T2 ON T1.productCode = T2.productCode INNER JOIN orders AS T3 ON T1.orderNumber = T3.orderNumber INNER JOIN customers AS T4 ON T3.customerNumber = T4.customerNumber WHERE T4.city = 'Boston' AND T4.salesRepEmployeeNumber IN ( SELECT employeeNumber FROM employees WHERE jobTitle = 'Sales Rep' ) ORDER BY T1.quantityOrdered DESC LIMIT 1", "index": 788, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['Sales Rep', 'President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['Boston', 'San Francisco']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n city text, -- example: ['Boston', 'Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nBoston is a city; amount of order = MULTIPLY(quantityOrdered, priceEach);\nWhat is the highest amount of order made by the sales representative in Boston? Please give the name of the product and amount.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2005-05-09', '2003-01-06', '2005-05-01', '2005-05-06', '2005-05-05', '2003-01-09']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n country text, -- example: ['USA', 'France']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n country text, -- example: ['USA', 'France']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntotal actual profit = SUM(SUBTRACT(priceEach, buyPrice)); American is a nationality of country = 'USA'; orderDate BETWEEN '2003-01-06' AND '2005-05-09';\nWhat is the total actual profit gained from orders made by American customers from 2003-01-06 to 2005-05-09?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT SUM(T2.priceEach - T1.buyPrice) FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode INNER JOIN orders AS T3 ON T2.orderNumber = T3.orderNumber INNER JOIN customers AS T4 ON T3.customerNumber = T4.customerNumber WHERE T3.orderDate > '2003-01-05' AND T3.orderDate < '2005-05-10'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT SUM(T2.priceEach - T1.buyPrice) FROM products AS T1 INNER JOIN orderdetails AS T2 ON T1.productCode = T2.productCode INNER JOIN orders AS T3 ON T2.orderNumber = T3.orderNumber INNER JOIN customers AS T4 ON T3.customerNumber = T4.customerNumber WHERE T3.orderDate > '2003-01-05' AND T3.orderDate < '2005-05-10'", "index": 789, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2005-05-09', '2003-01-06', '2005-05-01', '2005-05-06', '2005-05-05', '2003-01-09']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n country text, -- example: ['USA', 'France']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n country text, -- example: ['USA', 'France']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\ntotal actual profit = SUM(SUBTRACT(priceEach, buyPrice)); American is a nationality of country = 'USA'; orderDate BETWEEN '2003-01-06' AND '2005-05-09';\nWhat is the total actual profit gained from orders made by American customers from 2003-01-06 to 2005-05-09?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2005-01-07', '2005-01-06', '2005-01-05', '2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\norderDate between '2005-01-01' and '2005-12-31'; full address = addressLine1+addressLine2;\nFrom which branch does the sales representative employee who made the most sales in 2005? Please indicates its full address and phone number.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T3.addressLine1, T3.addressLine2, T3.phone FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber INNER JOIN customers AS T3 ON T2.customerNumber = T3.customerNumber INNER JOIN employees AS T4 ON T3.salesRepEmployeeNumber = T4.employeeNumber INNER JOIN offices AS T5 ON T4.officeCode = T5.officeCode WHERE STRFTIME('%Y', T2.orderDate) = '2005' AND T4.jobTitle = 'Sales Rep' ORDER BY T1.quantityOrdered DESC LIMIT 1", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T3.addressLine1, T3.addressLine2, T3.phone FROM orderdetails AS T1 INNER JOIN orders AS T2 ON T1.orderNumber = T2.orderNumber INNER JOIN customers AS T3 ON T2.customerNumber = T3.customerNumber INNER JOIN employees AS T4 ON T3.salesRepEmployeeNumber = T4.employeeNumber INNER JOIN offices AS T5 ON T4.officeCode = T5.officeCode WHERE STRFTIME('%Y', T2.orderDate) = '2005' AND T4.jobTitle = 'Sales Rep' ORDER BY T1.quantityOrdered DESC LIMIT 1", "index": 790, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2005-01-07', '2005-01-06', '2005-01-05', '2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\norderDate between '2005-01-01' and '2005-12-31'; full address = addressLine1+addressLine2;\nFrom which branch does the sales representative employee who made the most sales in 2005? Please indicates its full address and phone number.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-07-01', '2004-07-07', '2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2004-07-07', '2004-01-09', '2004-01-02', '2003-01-06', '2003-01-09']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage amount of payments = DIVIDE(SUM(amount), COUNT(customerNumber); first half of 2014 refers to paymentDate > = '2004-01-01' AND paymentDate < '2004-07-01;\nCalculate the average amount of payments made by customers during the first half of 2004.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT AVG(amount) FROM payments WHERE paymentDate BETWEEN '2004-01-01' AND '2004-06-30'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT AVG(amount) FROM payments WHERE paymentDate BETWEEN '2004-01-01' AND '2004-06-30'", "index": 791, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-07-01', '2004-07-07', '2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2004-07-07', '2004-01-09', '2004-01-02', '2003-01-06', '2003-01-09']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage amount of payments = DIVIDE(SUM(amount), COUNT(customerNumber); first half of 2014 refers to paymentDate > = '2004-01-01' AND paymentDate < '2004-07-01;\nCalculate the average amount of payments made by customers during the first half of 2004.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n buyPrice real, -- example: [48.81, 98.58]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nshipped orders refers to status = 'shipped'; year(shippedDate) = 2005; percentage = DIVIDE(SUM(customerNumber = 186)), COUNT(orderNumber)) as percentage;\nOf all the orders placed and shipped throughout the year 2005, what percentage of those orders corresponds to customer number 186?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT CAST(SUM(CASE WHEN customerNumber = 186 THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(orderNumber) FROM orders WHERE status = 'Shipped' AND shippedDate BETWEEN '2005-01-01' AND '2005-12-31'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT CAST(SUM(CASE WHEN customerNumber = 186 THEN 1 ELSE 0 END) AS REAL) * 100 / COUNT(orderNumber) FROM orders WHERE status = 'Shipped' AND shippedDate BETWEEN '2005-01-01' AND '2005-12-31'", "index": 792, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n buyPrice real, -- example: [48.81, 98.58]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n city text, -- example: ['Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nshipped orders refers to status = 'shipped'; year(shippedDate) = 2005; percentage = DIVIDE(SUM(customerNumber = 186)), COUNT(orderNumber)) as percentage;\nOf all the orders placed and shipped throughout the year 2005, what percentage of those orders corresponds to customer number 186?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['Sales Rep', 'President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['NYC', 'Nantes', 'Las Vegas']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['NYC', 'San Francisco', 'Boston']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull address = addressLine1 + addressLine2; NYC is a shortname of New York City.\nWhat is the full address of the office where the employee who is a sales representative for the customer whose business is located in the city of New York works?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T2.addressLine1, T2.addressLine2 FROM employees AS T1 INNER JOIN customers AS T2 ON T1.employeeNumber = T2.salesRepEmployeeNumber INNER JOIN offices AS T3 ON T1.officeCode = T3.officeCode WHERE T2.city = 'NYC' AND T1.jobTitle = 'Sales Rep'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T2.addressLine1, T2.addressLine2 FROM employees AS T1 INNER JOIN customers AS T2 ON T1.employeeNumber = T2.salesRepEmployeeNumber INNER JOIN offices AS T3 ON T1.officeCode = T3.officeCode WHERE T2.city = 'NYC' AND T1.jobTitle = 'Sales Rep'", "index": 793, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n jobTitle text, -- example: ['Sales Rep', 'President', 'VP Sales']\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n htmlDescription text,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['NYC', 'Nantes', 'Las Vegas']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['NYC', 'San Francisco', 'Boston']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nfull address = addressLine1 + addressLine2; NYC is a shortname of New York City.\nWhat is the full address of the office where the employee who is a sales representative for the customer whose business is located in the city of New York works?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Carousel DieCast Legends', 'Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nseller and product vendor are synonyms; Carousel DieCast Legends is a product vendor; profit = SUM(SUBTRACT(msrp, buyPrice));\nWhat profit can the seller Carousel DieCast Legends make from the sale of the product described as \"The perfect holiday or anniversary gift for executives\"?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT SUM(T2.MSRP - T2.buyPrice) FROM productlines AS T1 INNER JOIN products AS T2 ON T1.productLine = T2.productLine WHERE T2.productVendor = 'Carousel DieCast Legends' AND T1.textDescription LIKE '%perfect holiday or anniversary gift for executives%'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT SUM(T2.MSRP - T2.buyPrice) FROM productlines AS T1 INNER JOIN products AS T2 ON T1.productLine = T2.productLine WHERE T2.productVendor = 'Carousel DieCast Legends' AND T1.textDescription LIKE '%perfect holiday or anniversary gift for executives%'", "index": 794, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Carousel DieCast Legends', 'Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n contactFirstName text, -- example: ['Carine ', 'Jean']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nseller and product vendor are synonyms; Carousel DieCast Legends is a product vendor; profit = SUM(SUBTRACT(msrp, buyPrice));\nWhat profit can the seller Carousel DieCast Legends make from the sale of the product described as \"The perfect holiday or anniversary gift for executives\"?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['Boston', 'San Francisco']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Boston', 'Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage amount payment = AVG(amount);\nOf the clients whose businesses are located in the city of Boston, calculate which of them has a higher average amount of payment.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.customerNumber FROM customers AS T1 INNER JOIN payments AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.city = 'Boston' GROUP BY T1.customerNumber ORDER BY SUM(T2.amount) / COUNT(T2.paymentDate) DESC LIMIT 1", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T1.customerNumber FROM customers AS T1 INNER JOIN payments AS T2 ON T1.customerNumber = T2.customerNumber WHERE T1.city = 'Boston' GROUP BY T1.customerNumber ORDER BY SUM(T2.amount) / COUNT(T2.paymentDate) DESC LIMIT 1", "index": 795, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['Boston', 'San Francisco']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Boston', 'Nantes', 'Las Vegas']\n state text, -- example: ['NV', 'Victoria']\n postalCode text, -- example: ['44000', '83030']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\naverage amount payment = AVG(amount);\nOf the clients whose businesses are located in the city of Boston, calculate which of them has a higher average amount of payment.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Tseng', 'Murphy', 'Patterson']\n firstName text, -- example: ['Foon Yue', 'Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nDetailed address comprises addressLine1 and addressLine2;\nWhere's Foon Yue Tseng's office located at? Give the detailed address.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT T1.addressLine1, T1.addressLine2 FROM offices AS T1 INNER JOIN employees AS T2 ON T1.officeCode = T2.officeCode WHERE T2.firstName = 'Foon Yue' AND T2.lastName = 'Tseng'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT T1.addressLine1, T1.addressLine2 FROM offices AS T1 INNER JOIN employees AS T2 ON T1.officeCode = T2.officeCode WHERE T2.firstName = 'Foon Yue' AND T2.lastName = 'Tseng'", "index": 796, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n image blob,\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Tseng', 'Murphy', 'Patterson']\n firstName text, -- example: ['Foon Yue', 'Diane', 'Mary']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n PRIMARY KEY (orderNumber, productCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nDetailed address comprises addressLine1 and addressLine2;\nWhere's Foon Yue Tseng's office located at? Give the detailed address.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n contactLastName text, -- example: ['Schmitt', 'King']\n state text, -- example: ['NV', 'Victoria']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nProducts refer to productCode; Expected profits = SUBTRACT(MSRP, buyPrice);\nHow many products with the highest expected profits were sold in total?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT SUM(t2.quantityOrdered) FROM orderdetails AS t2 INNER JOIN ( SELECT t1.productCode FROM products AS t1 ORDER BY t1.MSRP - t1.buyPrice DESC LIMIT 1 ) AS t3 ON t2.productCode = t3.productCode", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT SUM(t2.quantityOrdered) FROM orderdetails AS t2 INNER JOIN ( SELECT t1.productCode FROM products AS t1 ORDER BY t1.MSRP - t1.buyPrice DESC LIMIT 1 ) AS t3 ON t2.productCode = t3.productCode", "index": 797, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productDescription text, -- example: ['This replica features working kickstand,', 'Turnable front wheels; steering function']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n contactLastName text, -- example: ['Schmitt', 'King']\n state text, -- example: ['NV', 'Victoria']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n PRIMARY KEY (officeCode)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nProducts refer to productCode; Expected profits = SUBTRACT(MSRP, buyPrice);\nHow many products with the highest expected profits were sold in total?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Petit Auto', 'Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2004-08-09', '2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2004-08-09', '2004-08-08', '2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-08-09', '2004-08-08', '2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nPetit Auto is name of customer; paymentDate = '2004-08-09';\nHow much did Petit Auto pay on 2004-08-09?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT t1.amount FROM payments AS t1 INNER JOIN customers AS t2 ON t1.customerNumber = t2.customerNumber WHERE t2.customerName = 'Petit Auto' AND t1.paymentDate = '2004-08-09'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT t1.amount FROM payments AS t1 INNER JOIN customers AS t2 ON t1.customerNumber = t2.customerNumber WHERE t2.customerName = 'Petit Auto' AND t1.paymentDate = '2004-08-09'", "index": 798, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n customerName text, -- example: ['Petit Auto', 'Atelier graphique', 'Signal Gift Stores']\n contactLastName text, -- example: ['Schmitt', 'King']\n phone text, -- example: ['40.32.2555', '7025551838']\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n city text, -- example: ['Nantes', 'Las Vegas']\n postalCode text, -- example: ['44000', '83030']\n country text, -- example: ['France', 'USA']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n creditLimit real, -- example: [21000.0, 71800.0]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2004-08-09', '2003-01-06', '2003-01-09']\n requiredDate date, -- example: ['2003-01-13', '2003-01-18']\n shippedDate date, -- example: ['2004-08-09', '2004-08-08', '2003-01-10', '2003-01-11']\n status text, -- example: ['Shipped', 'Resolved']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n quantityOrdered integer, -- example: [30, 50]\n priceEach real, -- price for each, example: [136.0, 55.09]\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n state text, -- example: ['CA', 'MA']\n country text, -- example: ['USA', 'France']\n postalCode text, -- example: ['94080', '02107']\n territory text, -- example: ['NA', 'EMEA']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n paymentDate date, -- example: ['2004-08-09', '2004-08-08', '2004-10-19', '2003-06-05']\n amount real, -- example: [6066.78, 14571.44]\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productName text, -- example: ['1969 Harley Davidson Ultimate Chopper', '1952 Alpine Renault 1300']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n productVendor text, -- example: ['Min Lin Diecast', 'Classic Metal Creations']\n quantityInStock integer, -- example: [7933, 7305]\n buyPrice real, -- example: [48.81, 98.58]\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n lastName text, -- example: ['Murphy', 'Patterson']\n firstName text, -- example: ['Diane', 'Mary']\n extension text, -- example: ['x5800', 'x4611']\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n textDescription text, -- example: ['Attention car enthusiasts: Make your wil', 'Our motorcycles are state of the art rep']\n htmlDescription text,\n image blob,\n PRIMARY KEY (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nPetit Auto is name of customer; paymentDate = '2004-08-09';\nHow much did Petit Auto pay on 2004-08-09?\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }
nl2sql
[ { "content": "You are a helpful assistant.", "role": "system" }, { "content": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nAddress comprises addressLine1 and addressLine2;\nWhere was the order No. 10383 shipped to? Show me the address.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "role": "user" } ]
nl2sql
{ "ground_truth": "SELECT t2.addressLine1, t2.addressLine2 FROM orders AS t1 INNER JOIN customers AS t2 ON t1.customerNumber = t2.customerNumber WHERE t1.orderNumber = '10383'", "style": "rule" }
{ "db_id": "car_retails.sqlite", "gt_sql": "SELECT t2.addressLine1, t2.addressLine2 FROM orders AS t1 INNER JOIN customers AS t2 ON t1.customerNumber = t2.customerNumber WHERE t1.orderNumber = '10383'", "index": 799, "question": "Task Overview:\nYou are a data science expert. Below, you are provided with a database schema and a natural language question. Your task is to understand the schema and generate a valid SQL query to answer the question.\n\nDatabase Engine:\nSQLite\n\nDatabase Schema:\nCREATE TABLE productlines (\n productLine text, -- example: ['Classic Cars', 'Motorcycles']\n PRIMARY KEY (productLine)\n);\n\nCREATE TABLE employees (\n employeeNumber integer, -- example: [1002, 1056]\n email text, -- example: ['dmurphy@classicmodelcars.com', 'mpatterso@classicmodelcars.com']\n officeCode text, -- example: ['1', '6']\n reportsTo integer, -- example: [1002, 1056]\n PRIMARY KEY (employeeNumber),\n CONSTRAINT fk_employees_officecode FOREIGN KEY (officeCode) REFERENCES offices (officeCode),\n CONSTRAINT fk_employees_reportsto FOREIGN KEY (reportsTo) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE offices (\n officeCode text, -- example: ['1', '2']\n city text, -- example: ['San Francisco', 'Boston']\n phone text, -- example: ['+1 650 219 4782', '+1 215 837 0825']\n addressLine1 text, -- example: ['100 Market Street', '1550 Court Place']\n addressLine2 text, -- example: ['Suite 300', 'Suite 102']\n PRIMARY KEY (officeCode)\n);\n\nCREATE TABLE orderdetails (\n orderNumber integer, -- example: [10100, 10101]\n productCode text, -- example: ['S18_1749', 'S18_2248']\n orderLineNumber integer, -- example: [3, 2]\n PRIMARY KEY (orderNumber, productCode)\n);\n\nCREATE TABLE customers (\n customerNumber integer, -- example: [103, 112]\n addressLine1 text, -- example: ['54, rue Royale', '8489 Strong St.']\n addressLine2 text, -- example: ['Level 3', 'Bronz Apt. 3/6 Tesvikiye']\n salesRepEmployeeNumber integer, -- sales representative employee number, example: [1370, 1166]\n PRIMARY KEY (customerNumber),\n CONSTRAINT fk_customers_salesrepemployeenumber FOREIGN KEY (salesRepEmployeeNumber) REFERENCES employees (employeeNumber)\n);\n\nCREATE TABLE payments (\n customerNumber integer, -- example: [103, 112]\n checkNumber text, -- example: ['HQ336336', 'JM555205']\n PRIMARY KEY (customerNumber, checkNumber),\n CONSTRAINT fk_payments_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE orders (\n orderNumber integer, -- example: [10100, 10101]\n orderDate date, -- example: ['2003-01-06', '2003-01-09']\n comments text, -- example: ['Check on availability.', 'Difficult to negotiate with customer. We']\n customerNumber integer, -- example: [363, 128]\n PRIMARY KEY (orderNumber),\n CONSTRAINT fk_orders_customernumber FOREIGN KEY (customerNumber) REFERENCES customers (customerNumber)\n);\n\nCREATE TABLE products (\n productCode text, -- example: ['S10_1678', 'S10_1949']\n productLine text, -- example: ['Motorcycles', 'Classic Cars']\n productScale text, -- example: ['1:10', '1:12']\n MSRP real, -- Manufacturer Suggested Retail Price, example: [95.7, 214.3]\n PRIMARY KEY (productCode),\n CONSTRAINT fk_products_productline FOREIGN KEY (productLine) REFERENCES productlines (productLine)\n);\nThis schema describes the database's structure, including tables, columns, primary keys, foreign keys, and any relevant relationships or constraints.\n\nQuestion:\nAddress comprises addressLine1 and addressLine2;\nWhere was the order No. 10383 shipped to? Show me the address.\n\nInstructions:\n- Make sure you only output the information that is asked in the question. If the question asks for a specific column, make sure to only include that column in the SELECT clause, nothing more.\n- The generated query should return all of the information asked in the question without any missing or extra information.\n- Before generating the final SQL query, please think through the steps of how to write the query.\n\nOutput Format:\nIn your answer, please enclose the generated SQL query in a code block:\n```sql\n-- Your SQL query\n```\n\nTake a deep breath and think step by step to find the correct SQL query.\n", "split": "train" }