instruction
stringlengths
53
549
output
stringlengths
30
2.33k
### Instruction: what's the name of the last medication patient 015-54876 was prescribed? ### Response:
SELECT medication.drugname FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '015-54876')) ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: Number of occurrences of display names lengths. ### Response:
SELECT U.range AS "display_name_length", COUNT(*) AS "number_of_occurences", ROUND((U.range / 600.0) * 100, 1) AS "character_limit_percentage_used" FROM (SELECT LENGTH(REPLACE(DisplayName, ' ', '')) AS range FROM Users WHERE DisplayName != '' AND NOT DisplayName IS NULL) AS U GROUP BY U.range ORDER BY U.range
### Instruction: How many civil liberties 2013 values are associated with a 2010 political rights value of 6, civil liberties 2012 values over 5, and political rights 2011 under 6? ### Response:
SELECT COUNT(civil_liberties_2013) FROM table_name_42 WHERE political_rights_2010 = 6 AND civil_liberties_2012 > 5 AND political_rights_2011 < 6
### Instruction: what is the top four of the frequent input event in 2101? ### 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) = '2101' GROUP BY intakeoutput.celllabel) AS t1 WHERE t1.c1 <= 4
### Instruction: subjects must have been diagnosed with type ii diabetes, with hba1c level >= 7 % and <= 11 % and a fasting glucose level <= 280 mg / dl. ### Response:
SELECT * FROM table_dev_43 WHERE diabetic = 'ii' AND (hemoglobin_a1c_hba1c >= 7 AND hemoglobin_a1c_hba1c <= 11) AND fasting_glucose <= 280
### Instruction: How many patients admitted as clinic referral (premature) were diagnosed with percutaneous transluminal coronary angioplasty status? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.admission_location = "CLINIC REFERRAL/PREMATURE" AND diagnoses.long_title = "Percutaneous transluminal coronary angioplasty status"
### Instruction: for the first time since 06/2101, when was patient 95892 prescribed a drug? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 95892) AND STRFTIME('%y-%m', prescriptions.startdate) >= '2101-06' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: when was patient 80671 prescribed a drug for the last time until 02/2103? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 80671) AND STRFTIME('%y-%m', prescriptions.startdate) <= '2103-02' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: what were the allergies during the current hospital visit that patient 015-58787 had? ### Response:
SELECT allergy.allergyname FROM allergy WHERE allergy.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '015-58787' AND patient.hospitaldischargetime IS NULL))
### Instruction: Are there any Modern English Grammar courses that complete the Other requirement ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course INNER JOIN area ON course.course_id = area.course_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE (area.area LIKE '%Modern English Grammar%' OR course.description LIKE '%Modern English Grammar%' OR course.name LIKE '%Modern English Grammar%') AND program_course.category LIKE '%Other%'
### Instruction: count the number of times spironolactone had been prescribed to patient 54894 since 5 years ago. ### Response:
SELECT COUNT(*) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 54894) AND prescriptions.drug = 'spironolactone' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-5 year')
### Instruction: what is the first medication that patient 41816 has been prescribed until 07/2102? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 41816) AND STRFTIME('%y-%m', prescriptions.startdate) <= '2102-07' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: what was the three most commonly carried out specimen tests until 2104? ### 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) <= '2104' GROUP BY microbiologyevents.spec_type_desc) AS t1 WHERE t1.c1 <= 3
### Instruction: provide the number of patients whose diagnoses short title is wegener's granulomatosis and drug route is sl? ### 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 = "Wegener's granulomatosis" AND prescriptions.route = "SL"
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, visualize a line chart about the change of salary over hire_date , and I want to order by the X in ascending. ### Response:
SELECT HIRE_DATE, SALARY FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY HIRE_DATE
### 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 , could you sort x-axis from high to low order? ### 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 LAST_NAME DESC
### Instruction: give me the number of patients whose diagnoses short title is chronic sinusitis nos and drug route is inhalation? ### 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 = "Chronic sinusitis NOS" AND prescriptions.route = "INHALATION"
### 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 a scatter chart about the correlation between employee_id and department_id . ### Response:
SELECT EMPLOYEE_ID, DEPARTMENT_ID FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: For those employees who did not have any job in the past, draw a bar chart about the distribution of job_id and the average of employee_id , and group by attribute job_id, display y-axis from high to low order please. ### 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) DESC
### Instruction: calculate the number of patients who have had a urine, voided specimen microbiology test since 3 years ago. ### Response:
SELECT COUNT(DISTINCT patient.uniquepid) FROM patient WHERE patient.patientunitstayid IN (SELECT microlab.patientunitstayid FROM microlab WHERE microlab.culturesite = 'urine, voided specimen' AND DATETIME(microlab.culturetakentime) >= DATETIME(CURRENT_TIME(), '-3 year'))
### 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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 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: How many patients are diagnosed with noninf gastroenterit nec and received medication through oral drug route? ### 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 = "Noninf gastroenterit NEC" AND prescriptions.route = "ORAL"
### Instruction: what was the last ward id that patient 27739 went since 3 years ago? ### Response:
SELECT transfers.wardid FROM transfers WHERE transfers.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 27739) AND NOT transfers.wardid IS NULL AND DATETIME(transfers.intime) >= DATETIME(CURRENT_TIME(), '-3 year') ORDER BY transfers.intime DESC LIMIT 1
### Instruction: How many patients were diagnosed with abnormal reaction to surgery or procedure and have their lab test category as chemistry? ### 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 = "Abn react-surg proc NEC" AND lab."CATEGORY" = "Chemistry"
### Instruction: when was the first time that liposomal cytarabine (depocyt) was prescribed to patient 64538? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 64538) AND prescriptions.drug = 'liposomal cytarabine (depocyt)' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: tell me the total amount of patient 31854's inputs on the current icu visit? ### Response:
SELECT SUM(inputevents_cv.amount) FROM inputevents_cv WHERE inputevents_cv.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 31854) AND icustays.outtime IS NULL)
### Instruction: what were the top three procedures for patients 20s? ### Response:
SELECT t1.treatmentname FROM (SELECT treatment.treatmentname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 20 AND 29) GROUP BY treatment.treatmentname) AS t1 WHERE t1.c1 <= 3
### Instruction: when is the last time patient 9566 was prescribed a drug since 07/2105? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 9566) AND STRFTIME('%y-%m', prescriptions.startdate) >= '2105-07' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: How many emergency hospital admission patients have calculus of bile duct without mention of cholecystitis or obstruction diagnoses? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.admission_type = "EMERGENCY" AND diagnoses.long_title = "Calculus of bile duct without mention of cholecystitis, without mention of obstruction"
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, for commission_pct, hire_date, visualize the trend, sort X in asc order. ### Response:
SELECT HIRE_DATE, COMMISSION_PCT FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY HIRE_DATE
### Instruction: provide the number of patients whose procedure long title is intraoperative cardiac pacemaker and lab test category is blood gas? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE procedures.long_title = "Intraoperative cardiac pacemaker" AND lab."CATEGORY" = "Blood Gas"
### Instruction: count the number of patients whose discharge location is disc-tran cancer/chldrn h and procedure short title is endosc destr stomach les? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.discharge_location = "DISC-TRAN CANCER/CHLDRN H" AND procedures.short_title = "Endosc destr stomach les"
### Instruction: count the number of patients whose discharge location is disc-tran cancer/chldrn h and procedure short title is endosc destr stomach les. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.discharge_location = "DISC-TRAN CANCER/CHLDRN H" AND procedures.short_title = "Endosc destr stomach les"
### Instruction: what is the number of patients whose ethnicity is hispanic/latino - puerto rican and lab test name is potassium, whole blood? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE demographic.ethnicity = "HISPANIC/LATINO - PUERTO RICAN" AND lab.label = "Potassium, Whole Blood"
### Instruction: what is patient 027-211129's last diagnosis? ### Response:
SELECT diagnosis.diagnosisname FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '027-211129')) ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### 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 department_id bin hire_date by time in a bar chart. ### Response:
SELECT HIRE_DATE, SUM(DEPARTMENT_ID) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200)
### Instruction: A stacked bar about the number of faults for different fault description and fault status of all the faults recoreded in the logs, I want to sort how many fault status in ascending order please. ### Response:
SELECT fault_status, COUNT(fault_status) FROM Fault_Log AS T1 JOIN Fault_Log_Parts AS T2 ON T1.fault_log_entry_id = T2.fault_log_entry_id GROUP BY fault_description, fault_status ORDER BY COUNT(fault_status)
### Instruction: find the number of patients who are diagnosed with postinflammatory pulmonary fibrosis and were ordered urine 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.short_title = "Postinflam pulm fibrosis" AND lab.fluid = "Urine"
### Instruction: What are the register ids of electoral registries that have the cross reference source system code 'Electoral' or 'Tax'? ### Response:
SELECT T1.electoral_register_id FROM electoral_register AS T1 JOIN cmi_cross_references AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id WHERE T2.source_system_code = 'Electoral' OR T2.source_system_code = 'Tax'
### Instruction: Get me the number of patients who have a chemistry lab test category along with diagnoses icd9 code 2760. ### 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 = "2760" AND lab."CATEGORY" = "Chemistry"
### Instruction: Who is , was , or will be teaching Information Industry ? ### 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 course ON course.course_id = course_offering.course_id WHERE course.name LIKE '%Information Industry%'
### Instruction: what was the total number of other myectomy procedures ordered since 5 years ago? ### 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 = 'other myectomy') AND DATETIME(procedures_icd.charttime) >= DATETIME(CURRENT_TIME(), '-5 year')
### Instruction: What was the Years in competition that had a Premiership of 1982, 1984, 1999, 2002-03, 2008-09-10? ### Response:
SELECT years_in_competition FROM table_name_2 WHERE premiership_years = "1982, 1984, 1999, 2002-03, 2008-09-10"
### Instruction: how many ACL 2012 papers have more than 7 citations ? ### Response:
SELECT DISTINCT (paper.paperid), COUNT(cite.citingpaperid) FROM cite, paper, venue WHERE paper.paperid = cite.citedpaperid AND paper.year = 2012 AND venue.venueid = paper.venueid AND venue.venuename = 'ACL' GROUP BY paper.paperid HAVING COUNT(cite.citingpaperid) > 7
### Instruction: how long was patient 43959's last stay at 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 = 43959) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime DESC LIMIT 1
### Instruction: Do you know how many ARABAM classes are there going to be offered for next semester ? ### Response:
SELECT COUNT(DISTINCT course_offering.course_id) FROM course, course_offering, semester WHERE course.course_id = course_offering.course_id AND course.department = 'ARABAM' AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: how many patients having diagnosis short title as dmi keto nt st uncntrld have lab test abnormal status as 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.short_title = "DMI keto nt st uncntrld" AND lab.flag = "delta"
### Instruction: provide the number of patients whose diagnosis short title is chr tot occlus cor artery 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 = "Chr tot occlus cor artry" AND lab."CATEGORY" = "Blood Gas"
### 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, draw a scatter chart about the correlation between manager_id and department_id . ### Response:
SELECT MANAGER_ID, DEPARTMENT_ID FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: since 2104 what was the four most common specimen test? ### 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) >= '2104' GROUP BY microbiologyevents.spec_type_desc) AS t1 WHERE t1.c1 <= 4
### Instruction: get the number of patients who have delta abnormal lab test status and are diagnosed with unspecified diabetic retinopathy. ### 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 = "Diabetic retinopathy NOS" AND lab.flag = "delta"
### Instruction: For those employees who was hired before 2002-06-21, show me about the distribution of job_id and the sum of employee_id , and group by attribute job_id in a bar chart, and I want to order JOB_ID in asc order. ### Response:
SELECT JOB_ID, SUM(EMPLOYEE_ID) FROM employees WHERE HIRE_DATE < '2002-06-21' GROUP BY JOB_ID ORDER BY JOB_ID
### Instruction: provide the number of patients whose diagnoses icd9 code is 5679 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.icd9_code = "5679" AND prescriptions.drug_type = "MAIN"
### Instruction: Percentage of users with rep=1 and with just a single question post. ### Response:
SELECT (1.0 * (SELECT COUNT(*) FROM (SELECT u.Id FROM (SELECT Id FROM Users WHERE Reputation = 1) AS u JOIN Posts AS p ON u.Id = p.OwnerUserId GROUP BY u.Id HAVING COUNT(*) = 1 AND MAX(p.PostTypeId) = 1) AS Chosen)) / (1.0 * (SELECT COUNT(*) FROM Users)) * 100
### Instruction: Recent posts by MathOverflow moderators. ### Response:
SELECT u.Id AS "user_link", u.LastAccessDate, p.CreationDate, p.Id AS "post_link" FROM Users AS u INNER JOIN Posts AS p ON p.OwnerUserId = u.Id WHERE u.Id IN (2, 3, 66, 121, 1409, 2000, 2926) ORDER BY p.CreationDate DESC LIMIT 100
### Instruction: vba questions daily, 60 days. ### Response:
SELECT DATEPART(ww, CreationDate) AS "week", COUNT(*) AS "vba_questions" FROM Posts WHERE Tags LIKE '%vba>%' AND PostTypeId = 1 AND CreationDate >= DATEADD(d, -60, GETDATE()) AND DATEPART(ww, CreationDate) < DATEPART(ww, GETDATE()) - 1 GROUP BY DATEPART(ww, CreationDate) ORDER BY DATEPART(ww, CreationDate)
### Instruction: what was the last value on the sodium lab test of patient 42956? ### Response:
SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 42956) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'sodium') ORDER BY labevents.charttime DESC LIMIT 1
### Instruction: calculate the number of patients who have had a skin scrapings microbiology test since 1 year ago. ### 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 = 'skin scrapings' AND DATETIME(microbiologyevents.charttime) >= DATETIME(CURRENT_TIME(), '-1 year'))
### 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 commission_pct and department_id . ### Response:
SELECT COMMISSION_PCT, DEPARTMENT_ID FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: what are the top three most frequently performed lab tests among the patients 50s? ### Response:
SELECT t1.labname FROM (SELECT lab.labname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 50 AND 59) GROUP BY lab.labname) AS t1 WHERE t1.c1 <= 3
### Instruction: Get the average size of a question for a tag grouped by quarter. ### Response:
SELECT DATEADD(quarter, DATEDIFF(quarter, 0, CreationDate), 0), AVG(LEN(p.Body)) FROM Posts AS p INNER JOIN PostTags AS pt ON pt.TagId = @TagId WHERE pt.PostId = p.Id AND p.PostTypeId = 1 GROUP BY DATEADD(quarter, DATEDIFF(quarter, 0, CreationDate), 0)
### Instruction: How many patients were diagnosed with atherosclerosis of native arteries of the extremities (unspecified) and were admitted before the year 2178? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.admityear < "2178" AND diagnoses.short_title = "Athscl extrm ntv art NOS"