instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: Show the number of the names of editors that are on the committee of journals with sales bigger than 3000, and display in descending by the total number. ### Response:
SELECT Name, COUNT(Name) FROM journal_committee AS T1 JOIN editor AS T2 ON T1.Editor_ID = T2.Editor_ID JOIN journal AS T3 ON T1.Journal_ID = T3.Journal_ID WHERE T3.Sales > 3000 GROUP BY Name ORDER BY COUNT(Name) DESC
### Instruction: count the number of patients whose admission year is less than 2124 and procedure long title is percutaneous [endoscopic] gastrostomy [peg]? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.admityear < "2124" AND procedures.long_title = "Percutaneous [endoscopic] gastrostomy [PEG]"
### Instruction: has patient 027-155345 received a diagnosis of bladder ca? ### Response:
SELECT COUNT(*) > 0 FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '027-155345')) AND diagnosis.diagnosisname = 'bladder ca'
### Instruction: What grades have I gotten in courses taught by Prof. Heather Southard ? ### Response:
SELECT DISTINCT student_record.grade FROM student_record INNER JOIN offering_instructor ON student_record.offering_id = offering_instructor.offering_id INNER JOIN instructor ON offering_instructor.instructor_id = instructor.instructor_id WHERE LOWER(instructor.name) LIKE '%Heather Southard%' AND student_record.student_id = 1
### Instruction: give me the number of patients whose ethnicity is black/african american and diagnoses long title is long-term (current) use of steroids? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.ethnicity = "BLACK/AFRICAN AMERICAN" AND diagnoses.long_title = "Long-term (current) use of steroids"
### Instruction: Posts containing two given words. ### Response:
SELECT Id AS "post_link", OwnerUserId AS "user_link", CreationDate, LastActivityDate, Score, ViewCount, Body FROM Posts WHERE (CONCAT(LOWER(Title), ' ', LOWER(Body)) LIKE '%##text1?cauchy##%') AND (CONCAT(LOWER(Title), ' ', LOWER(Body)) LIKE '%##text2?swartz##%') ORDER BY CreationDate DESC LIMIT 100
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, give me the comparison about employee_id over the last_name , show by the Y-axis in ascending. ### Response:
SELECT LAST_NAME, EMPLOYEE_ID FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY EMPLOYEE_ID
### Instruction: what was the last procedure time patient 26995 went through since 5 years ago? ### Response:
SELECT procedures_icd.charttime FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 26995) AND DATETIME(procedures_icd.charttime) >= DATETIME(CURRENT_TIME(), '-5 year') ORDER BY procedures_icd.charttime DESC LIMIT 1
### Instruction: count the number of patients whose diagnosis short title is 31-32 completed weeks gestation and urine as the lab test fluid ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.short_title = "31-32 comp wks gestation" AND lab.fluid = "Urine"
### Instruction: since 2102 tell me the three most common output events? ### Response:
SELECT d_items.label FROM d_items WHERE d_items.itemid IN (SELECT t1.itemid FROM (SELECT outputevents.itemid, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM outputevents WHERE STRFTIME('%y', outputevents.charttime) >= '2102' GROUP BY outputevents.itemid) AS t1 WHERE t1.c1 <= 3)
### Instruction: when was the first time a drug was prescribed to patient 61500 until 11/2105? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 61500) AND STRFTIME('%y-%m', prescriptions.startdate) <= '2105-11' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: count the number of patients whose diagnoses icd9 code is v489 and drug type is additive? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.icd9_code = "V489" AND prescriptions.drug_type = "ADDITIVE"
### Instruction: For those employees who did not have any job in the past, visualize a bar chart about the distribution of job_id and the sum of employee_id , and group by attribute job_id, and sort from high to low by the total number. ### Response:
SELECT JOB_ID, SUM(EMPLOYEE_ID) FROM employees WHERE NOT EMPLOYEE_ID IN (SELECT EMPLOYEE_ID FROM job_history) GROUP BY JOB_ID ORDER BY SUM(EMPLOYEE_ID) DESC
### Instruction: give me the number of patients whose diagnoses short title is ocl crtd art wo infrct and lab test abnormal status is abnormal? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.short_title = "Ocl crtd art wo infrct" AND lab.flag = "abnormal"
### Instruction: How many views did the question I answered get?. Finds every answer you wrote, and then looks how many views the question got. Kinda cool imo. ### Response:
SELECT A.ParentId AS "Question ID", Q.Id AS "post_link", Q.Tags AS "Tags", Q.ViewCount AS "Views" FROM Posts AS A INNER JOIN Posts AS Q ON Q.Id = A.ParentId WHERE A.PostTypeId = 2 AND A.OwnerUserId = @UserId ORDER BY Q.ViewCount DESC
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, what is the relationship between employee_id and commission_pct ? ### Response:
SELECT EMPLOYEE_ID, COMMISSION_PCT FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: what number of patients diagnosed with benign neo pituitary had drug type as additive? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Benign neo pituitary" AND prescriptions.drug_type = "ADDITIVE"
### Instruction: what was the three most frequent specimen test performed until 2102? ### Response:
SELECT t1.spec_type_desc FROM (SELECT microbiologyevents.spec_type_desc, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM microbiologyevents WHERE STRFTIME('%y', microbiologyevents.charttime) <= '2102' GROUP BY microbiologyevents.spec_type_desc) AS t1 WHERE t1.c1 <= 3
### Instruction: count the number of patients whose admission location is transfer from hosp/extram and procedure long title is creation of conduit between left ventricle and aorta? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.admission_location = "TRANSFER FROM HOSP/EXTRAM" AND procedures.long_title = "Creation of conduit between left ventricle and aorta"
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, show me about the distribution of hire_date and the average of department_id bin hire_date by time in a bar chart. ### Response:
SELECT HIRE_DATE, AVG(DEPARTMENT_ID) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200)
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, visualize the relationship between employee_id and commission_pct . ### Response:
SELECT EMPLOYEE_ID, COMMISSION_PCT FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: A bar chart for giveing me the number of the descriptions of the service types that cost more than 100, sort by the total number from high to low. ### Response:
SELECT Service_Type_Description, COUNT(Service_Type_Description) FROM Ref_Service_Types AS T1 JOIN Services AS T2 ON T1.Service_Type_Code = T2.Service_Type_Code WHERE T2.Product_Price > 100 GROUP BY Service_Type_Description ORDER BY COUNT(Service_Type_Description) DESC
### Instruction: count the number of patients whose diagnoses short title is bacterial pneumonia nos and drug type is main? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Bacterial pneumonia NOS" AND prescriptions.drug_type = "MAIN"
### Instruction: give me the number of patients whose diagnoses icd9 code is 28860 and drug route is dwell? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.icd9_code = "28860" AND prescriptions.route = "DWELL"
### Instruction: count the number of patients whose drug code is mica100i and lab test fluid is pleural? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE prescriptions.formulary_drug_cd = "MICA100I" AND lab.fluid = "Pleural"
### Instruction: provide the number of patients whose diagnosis short title is coagulation defect nec/nos and drug route is im. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Coagulat defect NEC/NOS" AND prescriptions.route = "IM"
### Instruction: what is the number of patients whose diagnoses short title is do not resusctate status and lab test category is hematology? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.short_title = "Do not resusctate status" AND lab."CATEGORY" = "Hematology"
### Instruction: count the number of patients whose diagnoses short title is nb obs genetc/metabl cnd and lab test fluid is ascites? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.short_title = "NB obs genetc/metabl cnd" AND lab.fluid = "Ascites"
### Instruction: New java developers and their technologies. ### Response:
SELECT t.Id, t.TagName, COUNT(DISTINCT p.Id) FROM PostTags AS pt JOIN Posts AS p ON PostId = p.Id JOIN Tags AS t ON TagId = t.Id JOIN Users ON p.OwnerUserId = Users.Id WHERE p.Id IN (SELECT PostId FROM PostTags WHERE TagId = 17) AND Age <= 24 AND PostTypeId = 1 GROUP BY t.Id, t.TagName ORDER BY 3 DESC
### Instruction: count the number of patients whose diagnoses short title is ac/chr syst/dia hrt fail and drug route is id? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Ac/chr syst/dia hrt fail" AND prescriptions.route = "ID"
### Instruction: For those employees who was hired before 2002-06-21, show me about the distribution of hire_date and the average of manager_id bin hire_date by time in a bar chart, could you list from low to high by the the average of manager id please? ### Response:
SELECT HIRE_DATE, AVG(MANAGER_ID) FROM employees WHERE HIRE_DATE < '2002-06-21' ORDER BY AVG(MANAGER_ID)
### Instruction: Is BIOPHYS 417 available to take in Spring 2013 ? ### Response:
SELECT COUNT(*) > 0 FROM course, course_offering, semester WHERE course.course_id = course_offering.course_id AND course.department = 'BIOPHYS' AND course.number = 417 AND semester.semester = 'Spring' AND semester.semester_id = course_offering.semester AND semester.year = 2013
### Instruction: what were the first drugs that were prescribed to patient 64185 since 137 months ago? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 64185) AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-137 month') ORDER BY prescriptions.startdate LIMIT 1
### Instruction: give me the number of patients whose diagnoses short title is opioid dependence-contin and lab test category is blood gas? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.short_title = "Opioid dependence-contin" AND lab."CATEGORY" = "Blood Gas"
### Instruction: how many days have passed since patient 002-4486 first stayed in ward 114 during this hospital visit? ### Response:
SELECT 1 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', patient.unitadmittime)) FROM patient WHERE patient.uniquepid = '002-4486' AND patient.wardid = 114 AND patient.hospitaldischargetime IS NULL ORDER BY patient.unitadmittime LIMIT 1
### Instruction: A bar chart for what are the number of the names of photos taken with the lens brand 'Sigma' or 'Olympus'?, and sort by the names in descending please. ### Response:
SELECT T1.name, COUNT(T1.name) FROM camera_lens AS T1 JOIN photos AS T2 ON T2.camera_lens_id = T1.id WHERE T1.brand = 'Sigma' OR T1.brand = 'Olympus' GROUP BY T1.name ORDER BY T1.name DESC
### Instruction: whats patient 9297 first ward id this year? ### Response:
SELECT transfers.wardid FROM transfers WHERE transfers.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 9297) AND NOT transfers.wardid IS NULL AND DATETIME(transfers.intime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') ORDER BY transfers.intime LIMIT 1
### Instruction: What is the lowest value for 1960, when the value for 2000 is less than 8.4, when the value for 1950 is greater than 3.5, and when the value for 1990 is less than 3.3? ### Response:
SELECT MIN(1960) FROM table_name_66 WHERE 2000 < 8.4 AND 1950 > 3.5 AND 1990 < 3.3
### Instruction: Distribution of users' up/down cast votes: graph. ### Response:
SELECT ROUND(100 * UpVotes / (UpVotes + DownVotes + 0.1), 0) AS UpRatio, COUNT(*) AS N FROM (SELECT * FROM Users AS U WHERE U.UpVotes + U.DownVotes > 100) AS a GROUP BY ROUND(100 * UpVotes / (UpVotes + DownVotes + 0.1), 0) ORDER BY UpRatio
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, find hire_date and the average of manager_id bin hire_date by time, and visualize them by a bar chart. ### Response:
SELECT HIRE_DATE, AVG(MANAGER_ID) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200)
### Instruction: what is the number of patients whose diagnoses icd9 code is 5770 and drug route is left eye? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.icd9_code = "5770" AND prescriptions.route = "LEFT EYE"
### Instruction: What is the last name of each student who is not allergic to any type of food? Count them with a bar chart, and show by the X in desc. ### Response:
SELECT LName, COUNT(LName) FROM Student WHERE NOT StuID IN (SELECT T1.StuID FROM Has_Allergy AS T1 JOIN Allergy_Type AS T2 ON T1.Allergy = T2.Allergy WHERE T2.AllergyType = "food") GROUP BY LName ORDER BY LName DESC
### Instruction: how many patients whose diagnoses short title is fetal/neonatal jaund nos and lab test abnormal status is abnormal? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.short_title = "Fetal/neonatal jaund NOS" AND lab.flag = "abnormal"
### Instruction: Who had the general classification when the trofeo fast team was Mapei-Bricobi, the points classification went to Mariano Piccoli and the mountains classification went to Marco Pantani in stage 22? ### Response:
SELECT "General classification" FROM table_53011 WHERE "Trofeo Fast Team" = 'mapei-bricobi' AND "Points classification" = 'mariano piccoli' AND "Mountains classification" = 'marco pantani' AND "Stage" = '22'
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, draw a bar chart about the distribution of hire_date and the average of employee_id bin hire_date by time. ### Response:
SELECT HIRE_DATE, AVG(EMPLOYEE_ID) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200)
### Instruction: which title has the same notes as night with a sky full of stars ? ### Response:
SELECT "title" FROM table_204_643 WHERE "title" <> 'manten no hoshi no yoru (満天の星の夜 night with a sky full of stars?)' AND "notes" = (SELECT "notes" FROM table_204_643 WHERE "title" = 'manten no hoshi no yoru (満天の星の夜 night with a sky full of stars?)')
### Instruction: what is five of the most frequent intake until 2104? ### Response:
SELECT t1.celllabel FROM (SELECT intakeoutput.celllabel, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM intakeoutput WHERE intakeoutput.cellpath LIKE '%intake%' AND STRFTIME('%y', intakeoutput.intakeoutputtime) <= '2104' GROUP BY intakeoutput.celllabel) AS t1 WHERE t1.c1 <= 5
### Instruction: Answer Rate for Lex Question. ### Response:
WITH diffs AS (SELECT CAST(a.CreationDate - Question.CreationDate AS FLOAT) AS d FROM Posts AS Question JOIN Posts AS a ON a.Id = Question.AcceptedAnswerId WHERE (Question.Tags LIKE '%<amazon-lex%' OR Question.Tags LIKE '%<aws-lex%') AND Question.CreationDate >= '2019-01-01') SELECT AVG(d), STDEV(d) FROM diffs
### Instruction: Which of my questions did Jon Skeet answer?. ### Response:
SELECT Questions.Title AS Question, 'https://stackoverflow.com/a/' + CAST(Answers.Id AS TEXT) AS Url FROM Posts AS Questions JOIN Posts AS Answers ON Answers.PostTypeId = 2 AND Answers.ParentId = Questions.Id WHERE Questions.OwnerUserId = @UserId AND Questions.PostTypeId = 1 AND Answers.OwnerUserId = @jonSkeetUserId
### Instruction: Top users by average answer score. ### Response:
SELECT a.OwnerUserId AS "user_link", a.OwnerDisplayName, AVG(CAST(a.Score AS FLOAT)) AS "average_score", SUM(a.Score) AS "total_score", COUNT(a.Id) AS "num_answers" FROM Posts AS a WHERE a.PostTypeId = 2 GROUP BY a.OwnerUserId, a.OwnerDisplayName ORDER BY AVG(a.Score) DESC LIMIT 100
### Instruction: Find the number of the enrollment date for all the tests that have 'Pass' result, and could you order by the Y-axis in desc? ### Response:
SELECT date_of_enrolment, COUNT(date_of_enrolment) FROM Student_Course_Enrolment AS T1 JOIN Student_Tests_Taken AS T2 ON T1.registration_id = T2.registration_id WHERE T2.test_result = "Pass" ORDER BY COUNT(date_of_enrolment) DESC
### Instruction: SO - Mobile OS - IOS. ### Response:
SELECT COUNT(*) AS PostCount, YEAR(P.CreationDate), MONTH(P.CreationDate) FROM Posts AS P INNER JOIN PostTags AS PT ON (P.Id = PT.PostId) INNER JOIN Tags AS T ON (PT.TagId = T.Id) WHERE T.TagName LIKE ('ios%') GROUP BY YEAR(P.CreationDate), MONTH(P.CreationDate) ORDER BY 2 DESC, 3 DESC
### Instruction: the number of times that patient 54631 had been prescribed sodium bicarbonate during the last hospital visit. ### Response:
SELECT COUNT(*) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 54631 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND prescriptions.drug = 'sodium bicarbonate'
### Instruction: tell me what are the top three most common procedures during this year? ### Response:
SELECT t1.treatmentname FROM (SELECT treatment.treatmentname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM treatment WHERE DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') GROUP BY treatment.treatmentname) AS t1 WHERE t1.c1 <= 3
### Instruction: How many american indian and alaska natives were diagnosed with other pulmonary insufficiency and were not elsewhere classified? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.ethnicity = "AMERICAN INDIAN/ALASKA NATIVE" AND diagnoses.long_title = "Other pulmonary insufficiency, not elsewhere classified"
### Instruction: Which Country has a Prominence (m) smaller than 1540, and a Height (m) smaller than 3530, and a Range of virunga mountains, and a Mountain of nyiragongo? ### Response:
SELECT "Country" FROM table_79544 WHERE "Prominence (m)" < '1540' AND "Height (m)" < '3530' AND "Range" = 'virunga mountains' AND "Mountain" = 'nyiragongo'
### Instruction: what was the four most common specimen test ordered until 2 years ago? ### Response:
SELECT t1.culturesite FROM (SELECT microlab.culturesite, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM microlab WHERE DATETIME(microlab.culturetakentime) <= DATETIME(CURRENT_TIME(), '-2 year') GROUP BY microlab.culturesite) AS t1 WHERE t1.c1 <= 4
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, show me about the distribution of hire_date and the sum of manager_id bin hire_date by weekday in a bar chart. ### Response:
SELECT HIRE_DATE, SUM(MANAGER_ID) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200)
### Instruction: for subjects treated with metformin: serum creatinine >= 1.5 mg / dl ( 133 umol / l ) for male or >= 1.4 mg / dl ( 124 umol ) for female ### Response:
SELECT * FROM table_train_252 WHERE metformin = 1 OR ((serum_creatinine >= 1.5 AND gender = 'male') OR (serum_creatinine >= 1.4 AND gender = 'female'))
### Instruction: what was patient 029-584's last id of the ward when they came to the hospital first time? ### Response:
SELECT patient.wardid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '029-584' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1) ORDER BY patient.unitadmittime DESC LIMIT 1
### Instruction: what is average age of patients whose primary disease is pneumonia;human immunodefiency virus;rule out tuberculosis and admission year is greater than or equal to 2195? ### Response:
SELECT AVG(demographic.age) FROM demographic WHERE demographic.diagnosis = "PNEUMONIA;HUMAN IMMUNODEFIENCY VIRUS;RULE OUT TUBERCULOSIS" AND demographic.admityear >= "2195"
### Instruction: count the number of patients whose ethnicity is black/african american and primary disease is coronary artery disease\coronary artery bypass graft /sda. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic WHERE demographic.ethnicity = "BLACK/AFRICAN AMERICAN" AND demographic.diagnosis = "CORONARY ARTERY DISEASE\CORONARY ARTERY BYPASS GRAFT /SDA"
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, draw a bar chart about the distribution of phone_number and department_id , order y-axis from low to high order. ### Response:
SELECT PHONE_NUMBER, DEPARTMENT_ID FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY DEPARTMENT_ID
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, a line chart shows the trend of manager_id over hire_date . ### Response:
SELECT HIRE_DATE, MANAGER_ID FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, draw a bar chart about the distribution of last_name and commission_pct , and sort names in descending order. ### Response:
SELECT LAST_NAME, COMMISSION_PCT FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY LAST_NAME DESC
### Instruction: provide the number of patients whose diagnoses short title is trnspl status-bne marrow and drug route is im? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Trnspl status-bne marrow" AND prescriptions.route = "IM"
### Instruction: count the number of patients whose diagnoses short title is subarachnoid hemorrhage and drug route is im? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Subarachnoid hemorrhage" AND prescriptions.route = "IM"
### Instruction: give me the number of patients whose drug code is posa200l and lab test fluid is urine? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE prescriptions.formulary_drug_cd = "POSA200L" AND lab.fluid = "Urine"
### Instruction: provide the number of patients whose primary disease is aortic valve insuffiency\aortic valve replacement /sda and lab test abnormal status is delta? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE demographic.diagnosis = "AORTIC VALVE INSUFFIENCY\AORTIC VALVE REPLACEMENT /SDA" AND lab.flag = "delta"
### Instruction: What are the response received dates for the documents described as 'Regular' or granted with more than 100? ### Response:
SELECT T1.response_received_date FROM Documents AS T1 JOIN Document_Types AS T2 ON T1.document_type_code = T2.document_type_code JOIN Grants AS T3 ON T1.grant_id = T3.grant_id WHERE T2.document_description = 'Regular' OR T3.grant_amount > 100
### Instruction: what is the number of patients whose diagnoses icd9 code is 23875 and drug route is neb? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.icd9_code = "23875" AND prescriptions.route = "NEB"
### Instruction: what is the number of patients whose diagnoses short title is ac diastolic hrt failure and drug route is tp? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Ac diastolic hrt failure" AND prescriptions.route = "TP"
### Instruction: how many patients are diagnosed with icd9 code 5770 and suggested with additive drug type? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.icd9_code = "5770" AND prescriptions.drug_type = "ADDITIVE"
### Instruction: Do you have a list of teachers for the human computer interaction courses ? ### Response:
SELECT DISTINCT instructor.name FROM instructor INNER JOIN offering_instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN course_offering ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN area ON course_offering.course_id = area.course_id WHERE area.area LIKE '%human computer interaction%'
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, draw a bar chart about the distribution of first_name and manager_id , and show by the X in ascending. ### Response:
SELECT FIRST_NAME, MANAGER_ID FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY FIRST_NAME
### Instruction: count the number of patients whose diagnoses short title is malig neo bladder nec and drug route is im? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Malig neo bladder NEC" AND prescriptions.route = "IM"
### Instruction: Which service id and type has the least number of participants? ### Response:
SELECT T3.service_id, T4.service_type_code FROM participants AS T1 JOIN participants_in_events AS T2 ON T1.participant_id = T2.participant_id JOIN events AS T3 ON T2.event_id = T3.event_id JOIN services AS T4 ON T3.service_id = T4.service_id GROUP BY T3.service_id ORDER BY COUNT(*) LIMIT 1
### Instruction: what was the number of patients who had a eye microbiology test in this year? ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT microbiologyevents.hadm_id FROM microbiologyevents WHERE microbiologyevents.spec_type_desc = 'eye' AND DATETIME(microbiologyevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year'))
### Instruction: tell me the number of patients on main drug type prescription who were diagnosed with cardiac complications, not elsewhere classified. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Surg compl-heart" AND prescriptions.drug_type = "MAIN"
### Instruction: provide the number of patients whose diagnosis icd9 code is 56731 and lab test category is blood gas. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.icd9_code = "56731" AND lab."CATEGORY" = "Blood Gas"
### Instruction: calculate patient 95470's stay length of the first stay in the icu. ### Response:
SELECT STRFTIME('%j', icustays.outtime) - STRFTIME('%j', icustays.intime) FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 95470) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime LIMIT 1
### Instruction: provide the number of patients whose diagnoses short title is abn react-renal dialysis and drug route is iv? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.short_title = "Abn react-renal dialysis" AND prescriptions.route = "IV"
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, draw a bar chart about the distribution of first_name and department_id , and I want to order X in asc order. ### Response:
SELECT FIRST_NAME, DEPARTMENT_ID FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY FIRST_NAME
### Instruction: what is the name of the drug patient 96728 was first prescribed since 179 months ago? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 96728) AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-179 month') ORDER BY prescriptions.startdate LIMIT 1
### Instruction: Top 20 voted CSS answers. ### Response:
SELECT COUNT(v.PostId) AS "Vote count", v.PostId AS "post_link", p.Body FROM Votes AS v INNER JOIN Tags AS t ON v.Id = t.Id INNER JOIN Posts AS p ON p.Id = v.PostId WHERE PostTypeId = 2 AND VoteTypeId = 2 AND t.TagName = 'CSS' GROUP BY v.PostId, p.Body ORDER BY 'Vote count' DESC LIMIT 20
### Instruction: Dead users with less than 200 rep, grouped by month they joined. ### Response:
SELECT YEAR(Users.CreationDate), MONTH(Users.CreationDate), COUNT(Users.CreationDate) FROM Posts JOIN Users ON Users.Id = Posts.OwnerUserId WHERE Users.Reputation < 200 GROUP BY YEAR(Users.CreationDate), MONTH(Users.CreationDate) ORDER BY YEAR(Users.CreationDate), MONTH(Users.CreationDate)
### Instruction: what is the number of patients whose diagnoses icd9 code is v6284 and drug type is base? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.icd9_code = "V6284" AND prescriptions.drug_type = "BASE"
### Instruction: what is the number of ven cath renal dialysis procedures since 2105? ### Response:
SELECT COUNT(*) FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'ven cath renal dialysis') AND STRFTIME('%y', procedures_icd.charttime) >= '2105'
### Instruction: For those employees who was hired before 2002-06-21, give me the comparison about the average of manager_id over the job_id , and group by attribute job_id by a bar chart, rank by the total number from high to low. ### Response:
SELECT JOB_ID, AVG(MANAGER_ID) FROM employees WHERE HIRE_DATE < '2002-06-21' GROUP BY JOB_ID ORDER BY AVG(MANAGER_ID) DESC
### Instruction: get me the number of patients with diagnoses icd9 code 1536 who are categorized under blood gas lab test. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.icd9_code = "1536" AND lab."CATEGORY" = "Blood Gas"
### Instruction: What are the number of start date of the apartment bookings made by female guests (gender code 'Female') for each year? Plot a bar chart, list total number in asc order. ### Response:
SELECT booking_start_date, COUNT(booking_start_date) FROM Apartment_Bookings AS T1 JOIN Guests AS T2 ON T1.guest_id = T2.guest_id WHERE T2.gender_code = "Female" ORDER BY COUNT(booking_start_date)
### Instruction: How many accounts are opened in each day for all accounts by the customer with first name 'Meaghan' ? Bin the account open day by year interval in a bar chart, rank by the X-axis in descending. ### Response:
SELECT date_account_opened, COUNT(date_account_opened) FROM Accounts AS T1 JOIN Customers AS T2 ON T1.customer_id = T2.customer_id WHERE T2.customer_first_name = 'Meaghan' ORDER BY date_account_opened DESC
### Instruction: tell me the length of time of patient 8324's last stay in icu. ### Response:
SELECT STRFTIME('%j', icustays.outtime) - STRFTIME('%j', icustays.intime) FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 8324) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime DESC LIMIT 1
### Instruction: calculate the total number of patients diagnosed with icd9 code 30390 who had their blood gas tested by lab ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.icd9_code = "30390" AND lab."CATEGORY" = "Blood Gas"
### Instruction: A bar chart for finding the number of the first name of students who are living in the Smith Hall, could you sort by the how many fname from low to high? ### Response:
SELECT Fname, COUNT(Fname) FROM Student AS T1 JOIN Lives_in AS T2 ON T1.stuid = T2.stuid JOIN Dorm AS T3 ON T3.dormid = T2.dormid WHERE T3.dorm_name = 'Smith Hall' GROUP BY Fname ORDER BY COUNT(Fname)
### Instruction: For those employees who did not have any job in the past, give me the comparison about the average of employee_id over the job_id , and group by attribute job_id by a bar chart, display by the y-axis in asc. ### Response:
SELECT JOB_ID, AVG(EMPLOYEE_ID) FROM employees WHERE NOT EMPLOYEE_ID IN (SELECT EMPLOYEE_ID FROM job_history) GROUP BY JOB_ID ORDER BY AVG(EMPLOYEE_ID)
### Instruction: have furosemide ever been prescribed to patient 1372 until 07/2101? ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 1372) AND prescriptions.drug = 'furosemide' AND STRFTIME('%y-%m', prescriptions.startdate) <= '2101-07'
### Instruction: How many patients were diagnosed with mouth and pharyngeal cancer and their lab test status was delta? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.long_title = "Carcinoma in situ of lip, oral cavity, and pharynx" AND lab.flag = "delta"
### Instruction: what is the number of patients whose diagnoses short title is peritoneal adhesions and lab test category is blood gas? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.short_title = "Peritoneal adhesions" AND lab."CATEGORY" = "Blood Gas"
### Instruction: count the number of patients whose admission type is emergency and procedure long title is endoscopic excision or destruction of lesion or tissue of stomach? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.admission_type = "EMERGENCY" AND procedures.long_title = "Endoscopic excision or destruction of lesion or tissue of stomach"