instruction
stringlengths
53
549
output
stringlengths
30
2.33k
### Instruction: count the number of people who were diagnosed with chr kidney dis stage iii until 4 years ago. ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT diagnoses_icd.hadm_id FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'chr kidney dis stage iii') AND DATETIME(diagnoses_icd.charttime) <= DATETIME(CURRENT_TIME(), '-4 year'))
### Instruction: how many hours have elapsed since patient 25733 had received an anion gap lab test for the first time in this hospital visit? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', labevents.charttime)) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'anion gap') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25733 AND admissions.dischtime IS NULL) ORDER BY labevents.charttime LIMIT 1
### Instruction: for the first time in 11/2104, what specimen test did patient 031-9128 get? ### Response:
SELECT microlab.culturesite FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-9128')) AND STRFTIME('%y-%m', microlab.culturetakentime) = '2104-11' ORDER BY microlab.culturetakentime LIMIT 1
### Instruction: what is the name of the drug that was last prescribed for patient 006-36108 during the previous month? ### 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 = '006-36108')) AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: Does any section of RCSSCI 360 start after 10:00 ? ### Response:
SELECT DISTINCT course_offering.end_time, course_offering.section_number, course_offering.start_time FROM course, course_offering, semester WHERE course_offering.start_time > '10:00' AND course.course_id = course_offering.course_id AND course.department = 'RCSSCI' AND course.number = 360 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: Top 2000 users ranked by average answer score. ### Response:
SELECT Users.Id AS "user_link", SUM(Posts.Score) AS "Upvotes", COUNT(*) AS "Answers", 1.0 * SUM(Posts.Score) / COUNT(*) AS "Ave. score", MAX(Posts.Score) AS "Highest score", 1.0 * MAX(Posts.Score) / SUM(Posts.Score) AS "Fraction votes from highest scoring answer" FROM Posts LEFT JOIN Users ON Posts.OwnerUserId = Users.Id WHERE Posts.PostTypeId = 2 GROUP BY Users.Id ORDER BY 'Ave. score' DESC LIMIT 2000
### Instruction: Is there a section for CLIMATE 440 after 10:00 ? ### Response:
SELECT DISTINCT course_offering.end_time, course_offering.section_number, course_offering.start_time FROM course, course_offering, semester WHERE course_offering.start_time > '10:00' AND course.course_id = course_offering.course_id AND course.department = 'CLIMATE' AND course.number = 440 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: Retrieve Answered Questions Tagged as 'Java' Created In The Month of January 2018. ### Response:
SELECT Q.Id, Q.AcceptedAnswerId, Q.CreationDate, Q.Score, Q.Body AS "Question Body", Q.Title AS "Question Title", A.Body AS "Answer Body", Q.Tags FROM Posts AS Q INNER JOIN Posts AS A ON Q.AcceptedAnswerId = A.Id WHERE Q.Tags = '<##tag?java##>' AND Q.CreationDate BETWEEN '2018-01-01' AND '2018-01-31' AND Q.Score >= 0 ORDER BY Q.Id
### Instruction: How many courses for each teacher? Show me a stacked bar chart The x-axis is teacher's first name and group by course description, and display by the X in ascending. ### Response:
SELECT EMP_FNAME, COUNT(EMP_FNAME) FROM CLASS AS T1 JOIN EMPLOYEE AS T2 ON T1.PROF_NUM = T2.EMP_NUM JOIN COURSE AS T3 ON T1.CRS_CODE = T3.CRS_CODE JOIN PROFESSOR AS T4 ON T2.EMP_NUM = T4.EMP_NUM GROUP BY CRS_DESCRIPTION, EMP_FNAME ORDER BY EMP_FNAME
### Instruction: Given a user ID and a site, attempt to find all comments on posts that are valid for the Cleanup Cre. ### Response:
SELECT DISTINCT c.PostId AS "post_link", c.Text AS "Comment Text", c.Score AS "Comment Score", c.CreationDate AS "Comment Date" FROM Comments AS c JOIN PostHistory AS h ON c.PostId = h.PostId JOIN Posts AS p ON c.PostId = p.Id WHERE c.UserId = '##UserId##' AND h.CreationDate > c.CreationDate AND c.Score > 0 AND p.OwnerUserId = h.UserId AND p.OwnerUserId != '##UserId##'
### Instruction: tell me the procedure that patient 81562 first had until 4 years ago? ### Response:
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT procedures_icd.icd9_code FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 81562) AND DATETIME(procedures_icd.charttime) <= DATETIME(CURRENT_TIME(), '-4 year') ORDER BY procedures_icd.charttime LIMIT 1)
### Instruction: what are the top four most frequent diagnoses among patients of age 20s until 4 years ago? ### Response:
SELECT t1.diagnosisname FROM (SELECT diagnosis.diagnosisname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 20 AND 29) AND DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-4 year') GROUP BY diagnosis.diagnosisname) AS t1 WHERE t1.c1 <= 4
### Instruction: Suggested edit approvals / rejections by month. ### Response:
WITH Raw AS (SELECT COALESCE(ApprovalDate, RejectionDate) AS CreationDate, CASE WHEN NOT ApprovalDate IS NULL THEN 1 ELSE 0 END AS Approved FROM SuggestedEdits) SELECT DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1) AS Month, CASE WHEN Approved = 1 THEN 'Approved' ELSE 'Rejected' END AS IsApproved, COUNT(*) AS Count FROM Raw GROUP BY DATEFROMPARTS(YEAR(CreationDate), MONTH(CreationDate), 1), Approved ORDER BY Month DESC, Approved
### Instruction: what are the maximum total costs of a hospital involving acute respiratory distress until 1 year ago? ### Response:
SELECT MAX(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT diagnosis.patientunitstayid FROM diagnosis WHERE diagnosis.diagnosisname = 'acute respiratory distress')) AND DATETIME(cost.chargetime) <= DATETIME(CURRENT_TIME(), '-1 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### 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, give me the comparison about the average of department_id over the job_id , and group by attribute job_id by a bar chart, and display Y-axis from low to high order. ### Response:
SELECT JOB_ID, AVG(DEPARTMENT_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY AVG(DEPARTMENT_ID)
### Instruction: what is the total number of input patient 027-22704 has received until 1091 days ago? ### Response:
SELECT SUM(intakeoutput.cellvaluenumeric) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '027-22704')) AND intakeoutput.cellpath LIKE '%intake%' AND DATETIME(intakeoutput.intakeoutputtime) <= DATETIME(CURRENT_TIME(), '-1091 day')
### Instruction: what's the average hospital cost if there is bradycardia - complete heart block until 2102? ### Response:
SELECT AVG(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT diagnosis.patientunitstayid FROM diagnosis WHERE diagnosis.diagnosisname = 'bradycardia - complete heart block')) AND STRFTIME('%y', cost.chargetime) <= '2102' GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: have patient 61500 had a closed renal biopsy procedure in 2105? ### Response:
SELECT COUNT(*) > 0 FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'closed renal biopsy') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 61500) AND STRFTIME('%y', procedures_icd.charttime) = '2105'
### Instruction: since 2103, what was the monthly minimum value of the rdw of patient 022-47232? ### Response:
SELECT MIN(lab.labresult) FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '022-47232')) AND lab.labname = 'rdw' AND STRFTIME('%y', lab.labresulttime) >= '2103' GROUP BY STRFTIME('%y-%m', lab.labresulttime)
### Instruction: After 14:00 A.M. , which section is SW 301 ? ### Response:
SELECT DISTINCT course_offering.end_time, course_offering.section_number, course_offering.start_time FROM course, course_offering, semester WHERE course_offering.start_time > '14:00' AND course.course_id = course_offering.course_id AND course.department = 'SW' AND course.number = 301 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### 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 bar chart about the distribution of job_id and the average of employee_id , and group by attribute job_id, sort Y-axis in asc order. ### Response:
SELECT JOB_ID, AVG(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY AVG(EMPLOYEE_ID)
### Instruction: how many days has it been from the last time patient 31854 received a glucose lab test on this hospital encounter? ### Response:
SELECT 1 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', labevents.charttime)) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'glucose') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 31854 AND admissions.dischtime IS NULL) ORDER BY labevents.charttime DESC LIMIT 1
### Instruction: In ORALHEAL 813 is there a lab when Prof. Tamar Carroll teaches it ? ### Response:
SELECT COUNT(*) = 0 FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN offering_instructor ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN instructor ON offering_instructor.instructor_id = instructor.instructor_id WHERE course.department = 'ORALHEAL' AND course.has_lab = 'N' AND course.number = 813 AND instructor.name LIKE '%Tamar Carroll%'
### Instruction: how many hours have pass since the last time patient 1561 stayed in ward 57 in this hospital encounter? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', transfers.intime)) FROM transfers WHERE transfers.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 1561 AND admissions.dischtime IS NULL)) AND transfers.wardid = 57 ORDER BY transfers.intime DESC LIMIT 1
### Instruction: on the current intensive care unit visit, list the daily maximum respiration of patient 006-157753. ### Response:
SELECT MAX(vitalperiodic.respiration) FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-157753') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.respiration IS NULL GROUP BY STRFTIME('%y-%m-%d', vitalperiodic.observationtime)
### Instruction: in total, count the number of times patient 021-79656 had been prescribed tramadol 50 mg tab until 2104. ### Response:
SELECT COUNT(*) FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-79656')) AND medication.drugname = 'tramadol 50 mg tab' AND STRFTIME('%y', medication.drugstarttime) <= '2104'
### Instruction: what's the last diagnosis patient 83709 got in the last hospital visit? ### Response:
SELECT d_icd_diagnoses.short_title FROM d_icd_diagnoses WHERE d_icd_diagnoses.icd9_code IN (SELECT diagnoses_icd.icd9_code FROM diagnoses_icd WHERE diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 83709 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) ORDER BY diagnoses_icd.charttime DESC LIMIT 1)
### Instruction: Who added this [tag] to the question?. ### Response:
SELECT MAX(CreationDate), PostId AS "post_link", FIRST_USER AS "user_link" FROM (SELECT FIRST_VALUE(PH.UserId) OVER (PARTITION BY PH.PostId ORDER BY PH.CreationDate) AS FIRST_USER, * FROM PostHistory AS PH WHERE (PH.PostHistoryTypeId = @reTag OR PH.PostHistoryTypeId = @initTag) AND PH.Text LIKE '%<' + @tagToSearch + '>%') AS P WHERE FIRST_USER = 8404453 GROUP BY PostId, FIRST_USER
### Instruction: How many answer upvotes will I get in average for each tag?. ### Response:
SELECT TagName, CAST(COUNT(Votes.Id) AS FLOAT) / COUNT(DISTINCT Posts.Id) AS UpVotes FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.Id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id AND VoteTypeId = 2 WHERE Posts.PostTypeId = 2 GROUP BY TagName AND CAST(COUNT(Votes.Id) AS FLOAT) / COUNT(DISTINCT Posts.Id) > 1 ORDER BY UpVotes DESC
### Instruction: how many hours has it been since the first time patient 004-79017 received a treatment in their current hospital encounter? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', treatment.treatmenttime)) FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '004-79017' AND patient.hospitaldischargetime IS NULL)) ORDER BY treatment.treatmenttime LIMIT 1
### Instruction: how many patients until 4 years ago received oxygen therapy (> 60%) - 70-80% two times? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, COUNT(*) AS c1 FROM patient WHERE patient.patientunitstayid = (SELECT treatment.patientunitstayid FROM treatment WHERE treatment.treatmentname = 'oxygen therapy (> 60%) - 70-80%' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-4 year')) GROUP BY patient.uniquepid) AS t1 WHERE t1.c1 = 2
### Instruction: Evolution of mean score and number of questions in 2015 by week. Evolution of mean score and number of questions in 2015 by week ### Response:
SELECT TIME_TO_STR(p.CreationDate, '%W') AS weekOfCreation, AVG(p.Score) AS meanQuestionScore, COUNT(p.Id) AS NumberOfPosts FROM Posts AS p WHERE p.PostTypeId = 1 AND TIME_TO_STR(p.CreationDate, '%Y') = 2015 GROUP BY TIME_TO_STR(p.CreationDate, '%W') ORDER BY TIME_TO_STR(p.CreationDate, '%W')
### Instruction: Top 50 Sri Lankan Developers who are on Stackoverflow. ### Response:
SELECT ROW_NUMBER() OVER (ORDER BY Users.Reputation DESC) AS "#", Users.Id AS "user_link", Users.Location, Users.Reputation, Users.UpVotes, Users.DownVotes, (SELECT COUNT(*) FROM Posts AS PQ WHERE PostTypeId = 1 AND PQ.OwnerUserId = Users.Id) AS "questions", (SELECT COUNT(*) FROM Posts AS PA WHERE PostTypeId = 2 AND PA.OwnerUserId = Users.Id) AS "answers" FROM Users WHERE LOWER(Location) LIKE '%lanka%' ORDER BY Reputation DESC LIMIT 50
### Instruction: how many days have passed since the first time during their current hospital encounter that patient 031-13920 had a procedure performed? ### Response:
SELECT 1 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', treatment.treatmenttime)) FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-13920' AND patient.hospitaldischargetime IS NULL)) ORDER BY treatment.treatmenttime LIMIT 1
### Instruction: how many hours have passed since the last time patient 021-80293 during this hospital encounter went through a procedure? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', treatment.treatmenttime)) FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-80293' AND patient.hospitaldischargetime IS NULL)) ORDER BY treatment.treatmenttime DESC LIMIT 1
### Instruction: Old Closed Posts with no answers that weren't closed as duplicate, migrated or merged. ### Response:
SELECT CONCAT('id', 'post_link'), Id, ClosedDate, Score, ViewCount FROM Posts AS q WHERE PostTypeId = 1 AND CreationDate < (CURRENT_TIMESTAMP() - 30) AND COALESCE(AnswerCount, 0) = 0 AND NOT ClosedDate IS NULL AND Id NOT IN (SELECT PostId FROM PostHistory WHERE (PostHistoryTypeId = 10 AND Comment IN (1)) OR PostHistoryTypeId IN (17, 18, 35, 37, 38)) ORDER BY ClosedDate
### Instruction: when patient 028-55503 was getting a prescription for the last time during a month before? ### Response:
SELECT medication.drugstarttime FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '028-55503')) AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: what was the name of the drugs that patient 030-75705 was prescribed first the previous month. ### 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 = '030-75705')) AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY medication.drugstarttime LIMIT 1
### Instruction: when is the last time patient 002-13510 was prescribed medication via po in the first hospital visit? ### Response:
SELECT medication.drugstarttime FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '002-13510' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND medication.routeadmin = 'po' ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: Which classes are allowed for PreMajor this coming semester ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program, program_course, semester WHERE course.course_id = course_offering.course_id AND program_course.category LIKE '%PreMajor%' AND program_course.course_id = course.course_id AND program.name LIKE '%CS-LSA%' AND program.program_id = program_course.program_id AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: Find best answer to my question. ### Response:
SELECT Q.Title, Q.Body, A.Body, A.Score, Q.Id AS "post_link" FROM Posts AS Q JOIN Posts AS A ON (Q.AcceptedAnswerId = A.Id) WHERE Q.PostTypeId = 1 AND A.PostTypeId = 2 AND (Q.Title LIKE '%' + REPLACE(@question, ' ', '% ') + '%' OR Q.Body LIKE '%' + REPLACE(@question, ' ', '% ') + '%') ORDER BY DIFFERENCE(@question, Q.Title), DIFFERENCE(@question, Q.Body), Q.Score DESC, A.Score DESC LIMIT 1
### Instruction: provide me the number of patients diagnosed with hypertensive chronic kidney disease, unspecified, with chronic kidney disease stage v or end stage renal disease who had csf lab test done. ### 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 = "Hypertensive chronic kidney disease, unspecified, with chronic kidney disease stage V or end stage renal disease" AND lab.fluid = "Cerebrospinal Fluid (CSF)"
### Instruction: has patient 17667 been prescribed in this year acetaminophen (liquid), ns, or 0.9% sodium chloride? ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17667) AND prescriptions.drug IN ('acetaminophen (liquid)', 'ns', '0.9% sodium chloride') AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')
### Instruction: Total questions and answers per calendar month. ### Response:
SELECT TIME_TO_STR(CreationDate, '%Y') * 100 + TIME_TO_STR(CreationDate, '%m') AS YearMonth, SUM(CASE WHEN ParentId IS NULL THEN 1 ELSE 0 END) AS TotalQuestions, SUM(CASE WHEN NOT ParentId IS NULL THEN 1 ELSE 0 END) AS TotalAnswers FROM Posts GROUP BY TIME_TO_STR(CreationDate, '%Y'), TIME_TO_STR(CreationDate, '%m') ORDER BY TIME_TO_STR(CreationDate, '%Y'), TIME_TO_STR(CreationDate, '%m')
### Instruction: Most viewed duplicates missing the 'Possible Duplicate' bit. ### Response:
SELECT p.Score, p.Id AS "post_link", p.ViewCount, p.OwnerUserId AS "user_link", p.CreationDate FROM Posts AS p INNER JOIN PostHistory AS h ON h.PostId = p.Id WHERE NOT p.ClosedDate IS NULL AND p.ClosedDate = h.CreationDate AND h.PostHistoryTypeId = 10 AND h.Comment = '1' AND NOT p.Body LIKE '%<strong>Possible Duplicate:</strong>%' AND NOT p.Body LIKE '%<strong>Possible Duplicates:</strong>%' ORDER BY p.ViewCount DESC
### Instruction: Research Health Ed is taught by whom this semester ? ### 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 INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE course.name LIKE '%Research Health Ed%' AND semester.semester = 'WN' AND semester.year = 2016
### Instruction: what was the name of the organism detected in patient 71091's last urine microbiology test until 2 months ago? ### Response:
SELECT microbiologyevents.org_name FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 71091) AND microbiologyevents.spec_type_desc = 'urine' AND NOT microbiologyevents.org_name IS NULL AND DATETIME(microbiologyevents.charttime) <= DATETIME(CURRENT_TIME(), '-2 month') ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: what is the maximum hospital cost for a procedure that involves sedative agent - propofol until 3 years ago? ### Response:
SELECT MAX(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT treatment.patientunitstayid FROM treatment WHERE treatment.treatmentname = 'sedative agent - propofol')) AND DATETIME(cost.chargetime) <= DATETIME(CURRENT_TIME(), '-3 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: Which 2007/ 08 has a 2010/ 11 of not held, and a 2011/ 12 of not held, and a 2008/ 09 of not held, and a 2006/ 07 of lq? ### Response:
SELECT "2007/ 08" FROM table_37818 WHERE "2010/ 11" = 'not held' AND "2011/ 12" = 'not held' AND "2008/ 09" = 'not held' AND "2006/ 07" = 'lq'
### Instruction: tell me what the total output the previous day is for patient 006-2586. ### Response:
SELECT SUM(intakeoutput.cellvaluenumeric) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-2586')) AND intakeoutput.cellpath LIKE '%output%' AND DATETIME(intakeoutput.intakeoutputtime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-1 day')
### Instruction: list the patient ids of patients who had been diagnosed with jt contracture-jt nec since 5 years ago. ### Response:
SELECT admissions.subject_id FROM admissions WHERE admissions.hadm_id IN (SELECT diagnoses_icd.hadm_id FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'jt contracture-jt nec') AND DATETIME(diagnoses_icd.charttime) >= DATETIME(CURRENT_TIME(), '-5 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 a bar chart about the distribution of job_id and the sum of manager_id , and group by attribute job_id, I want to sort by the Y in descending. ### Response:
SELECT JOB_ID, SUM(MANAGER_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY SUM(MANAGER_ID) DESC
### Instruction: what was the last heart rate value patient 26886 had? ### Response:
SELECT chartevents.valuenum FROM chartevents WHERE chartevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 26886)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'heart rate' AND d_items.linksto = 'chartevents') ORDER BY chartevents.charttime DESC LIMIT 1
### Instruction: what is the maximum total cost to the hospital that includes a vent rate lab test during the previous year? ### Response:
SELECT MAX(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT lab.patientunitstayid FROM lab WHERE lab.labname = 'vent rate')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: What is the highest Crude Death Rate (per 1000), when Natural Change (Per 1000) is greater than 16.1, when Natural Change is 5,049, and when Crude Birth Rate (Per 1000) is less than 27.1? ### Response:
SELECT MAX("Crude death rate (per 1000)") FROM table_40964 WHERE "Natural change (per 1000)" > '16.1' AND "Natural change" = '5,049' AND "Crude birth rate (per 1000)" < '27.1'
### Instruction: what was the last value of patient 022-44805's bun laboratory test since 12/2101? ### Response:
SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '022-44805')) AND lab.labname = 'bun' AND STRFTIME('%y-%m', lab.labresulttime) >= '2101-12' ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: what was the name of the organism found in the microbiology test of the first other of patient 031-3355 on the current hospital visit? ### Response:
SELECT microlab.organism FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-3355' AND patient.hospitaldischargetime IS NULL)) AND microlab.culturesite = 'other' ORDER BY microlab.culturetakentime LIMIT 1
### Instruction: list the ids of all those patients diagnosed with rupt abd aortic aneurysm in 2103. ### Response:
SELECT admissions.subject_id FROM admissions WHERE admissions.hadm_id IN (SELECT diagnoses_icd.hadm_id FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'rupt abd aortic aneurysm') AND STRFTIME('%y', diagnoses_icd.charttime) = '2103')
### Instruction: What would be the correct year in the 1940s, if the 1980s is before 1986, the 1990s is before 1995, the 1970s is before 1973, and the 2000s are after 2001? ### Response:
SELECT "1940s" FROM table_15596 WHERE "1980s" < '1986' AND "1990s" < '1995' AND "1970s" < '1973' AND "2000s" > '2001'
### Instruction: among the patients aged 60 or above in this year, what were the top five most frequent procedures? ### 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 >= 60) AND DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') GROUP BY treatment.treatmentname) AS t1 WHERE t1.c1 <= 5
### Instruction: what the first height of patient 004-86136 in 08/this year. ### Response:
SELECT patient.admissionheight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '004-86136') AND NOT patient.admissionheight IS NULL AND DATETIME(patient.unitadmittime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', patient.unitadmittime) = '08' ORDER BY patient.unitadmittime LIMIT 1
### 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, return a bar chart about the distribution of hire_date and the average of employee_id bin hire_date by weekday, and rank by the total number in desc. ### Response:
SELECT HIRE_DATE, AVG(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY AVG(EMPLOYEE_ID) DESC
### Instruction: what was the first time patient 28959 had the maximum platelet count value until 06/2103? ### Response:
SELECT labevents.charttime FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 28959) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'platelet count') AND STRFTIME('%y-%m', labevents.charttime) <= '2103-06' ORDER BY labevents.valuenum DESC, labevents.charttime LIMIT 1
### 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 bar chart shows the distribution of hire_date and the average of employee_id bin hire_date by time, and rank in descending by the y-axis. ### Response:
SELECT HIRE_DATE, AVG(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY AVG(EMPLOYEE_ID) DESC
### Instruction: What is the id and name of the department store that has both marketing and managing department? ### Response:
SELECT T2.dept_store_id, T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "marketing" INTERSECT SELECT T2.dept_store_id, T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "managing"
### Instruction: tell me the name of the specimen test that patient 031-19622 had last received during the last hospital visit? ### Response:
SELECT microlab.culturesite FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-19622' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) ORDER BY microlab.culturetakentime DESC LIMIT 1
### Instruction: i'd like to arrange a trip to BALTIMORE on 1 1 ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service, city, date_day, days, flight WHERE city.city_code = airport_service.city_code AND city.city_name = 'BALTIMORE' AND date_day.day_number = 1 AND date_day.month_number = 1 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = airport_service.airport_code
### Instruction: Does Christopher Peterson provide teaching for any upper-level courses ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN offering_instructor ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE instructor.name LIKE '%Christopher Peterson%' AND program_course.category LIKE 'ULCS'
### Instruction: Show the hours of the day a user is most active. Gets the hours in which a user has been active (enables you to see when a user sleeps!) ### Response:
WITH hours AS (SELECT TIME_TO_STR(CreationDate, '%I') AS HoursSeen FROM Posts WHERE OwnerUserId = '##UserId##' UNION ALL SELECT TIME_TO_STR(CreationDate, '%I') AS HoursSeen FROM Comments WHERE UserId = '##UserId##') SELECT HoursSeen AS Hour, COUNT(*) AS Count, '|' + REPEAT('*', COUNT(*)) AS Graph FROM hours GROUP BY HoursSeen ORDER BY HoursSeen
### Instruction: Non-CW posts with most revisions counting towards limit. ### Response:
SELECT Posts.Id AS "post_link", COUNT(DISTINCT RevisionGUID) AS Revisions FROM PostHistory JOIN Posts ON PostHistory.PostId = Posts.Id WHERE Posts.CommunityOwnedDate IS NULL AND Posts.OwnerUserId = '##UserId##' AND PostHistory.PostHistoryTypeId IN (1, 2, 3, 4, 5, 6, 7, 8, 9) GROUP BY Posts.Id HAVING COUNT(DISTINCT RevisionGUID) > 2 ORDER BY COUNT(DISTINCT RevisionGUID) DESC
### Instruction: tell me the name of the last specimen test that patient 4758 in 07/this year received? ### Response:
SELECT microbiologyevents.spec_type_desc FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 4758) AND DATETIME(microbiologyevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', microbiologyevents.charttime) = '07' ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: when was the last time since 179 months ago that patient 1114 had the maximum magnesium? ### Response:
SELECT labevents.charttime FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 1114) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'magnesium') AND DATETIME(labevents.charttime) >= DATETIME(CURRENT_TIME(), '-179 month') ORDER BY labevents.valuenum DESC, labevents.charttime DESC LIMIT 1
### Instruction: among patients of age 50s during the previous year, what were the top four most frequent lab tests? ### 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) AND DATETIME(lab.labresulttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY lab.labname) AS t1 WHERE t1.c1 <= 4
### Instruction: among those with age 40s in 2101 what was the top four most frequent diagnosis? ### Response:
SELECT t1.diagnosisname FROM (SELECT diagnosis.diagnosisname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 40 AND 49) AND STRFTIME('%y', diagnosis.diagnosistime) = '2101' GROUP BY diagnosis.diagnosisname) AS t1 WHERE t1.c1 <= 4
### Instruction: what is the average total cost of a hospital that includes laboratory testing for alkaline phos. since 2105? ### Response:
SELECT AVG(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT lab.patientunitstayid FROM lab WHERE lab.labname = 'alkaline phos.')) AND STRFTIME('%y', cost.chargetime) >= '2105' GROUP BY cost.patienthealthsystemstayid) AS t1
### 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, show me about the distribution of hire_date and the sum of employee_id bin hire_date by time in a bar chart, and rank total number from low to high order. ### Response:
SELECT HIRE_DATE, SUM(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY SUM(EMPLOYEE_ID)
### Instruction: Count of active answerers by week. Count of the users posted at least 3 answers on that week ### Response:
WITH Raw AS (SELECT Id, DATEADD(day, 7 * (DATEDIFF(day, '1970-01-05', CreationDate) / 7), '1970-01-05') AS Week, OwnerUserId AS UserId FROM Posts WHERE PostTypeId = 2 AND OwnerUserId > 0), Raw2 AS (SELECT Week, UserId, COUNT(*) AS PostCount FROM Raw GROUP BY Week, UserId) SELECT Week, COUNT(*) AS UserCount FROM Raw2 WHERE PostCount > 3 GROUP BY Week ORDER BY Week
### Instruction: what is the total average cost of a hospital that includes a promyelocytes lab test in the last year? ### Response:
SELECT AVG(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.hadm_id IN (SELECT labevents.hadm_id FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'promyelocytes')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY cost.hadm_id) AS t1
### Instruction: what paper did ras bodik and ameet soni write together ? ### Response:
SELECT DISTINCT WRITES_0.paperid FROM author AS AUTHOR_0, author AS AUTHOR_1, writes AS WRITES_0, writes AS WRITES_1 WHERE AUTHOR_0.authorname = 'ras bodik' AND AUTHOR_1.authorname = 'ameet soni' AND WRITES_0.authorid = AUTHOR_0.authorid AND WRITES_1.authorid = AUTHOR_1.authorid AND WRITES_1.paperid = WRITES_0.paperid
### Instruction: was there any organism detected in patient 10811's last stool microbiological test until 01/2104? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 10811) AND microbiologyevents.spec_type_desc = 'stool' AND NOT microbiologyevents.org_name IS NULL AND STRFTIME('%y-%m', microbiologyevents.charttime) <= '2104-01' ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: What is the average tourism receipts in millions of US dollars in 2011 with less than 1.141 million of 2011 tourist arrivals and more than 1,449 tourism receipts in 2011 US dollars per arrival? ### Response:
SELECT AVG(tourism_receipts__2011___millions_of_us) AS $_ FROM table_name_41 WHERE tourist_arrivals__2011___millions_ < 1.141 AND tourism_receipts__2011___us$_per_arrival_ > 1 OFFSET 449
### Instruction: when did patient 029-16431 have a base excess test for the last time when they came to the hospital last time? ### Response:
SELECT lab.labresulttime FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '029-16431' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND lab.labname = 'base excess' ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: For NESLANG 451 is NESLANG 499 required ? ### Response:
SELECT COUNT(*) > 0 FROM course AS COURSE_0, course AS COURSE_1, course_prerequisite WHERE COURSE_0.course_id = course_prerequisite.pre_course_id AND COURSE_0.department = 'NESLANG' AND COURSE_0.number = 499 AND COURSE_1.course_id = course_prerequisite.course_id AND COURSE_1.department = 'NESLANG' AND COURSE_1.number = 451
### Instruction: how many people had been diagnosed with dis plas protein met nec until 2104? ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT diagnoses_icd.hadm_id FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'dis plas protein met nec') AND STRFTIME('%y', diagnoses_icd.charttime) <= '2104')
### Instruction: when did patient 97330 first had the maximum value of sodium since 03/2102? ### Response:
SELECT labevents.charttime FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 97330) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'sodium') AND STRFTIME('%y-%m', labevents.charttime) >= '2102-03' ORDER BY labevents.valuenum DESC, labevents.charttime LIMIT 1
### Instruction: Find my comments with link to them. ### Response:
SELECT *, 'http://stackoverflow.com/questions/' + CAST(PostAnswers.ParentId AS TEXT(20)) + '/title/' + CAST(Comments.PostId AS TEXT(20)) + '?noredirect=1#comment' + CAST(Comments.Id AS TEXT(20)) + '_' + CAST(Comments.PostId AS TEXT(20)) FROM Comments LEFT OUTER JOIN Posts AS PostAnswers ON Comments.PostId = PostAnswers.Id WHERE Comments.UserId = '##UserId##' ORDER BY Comments.Score DESC
### Instruction: Next Summer after 21:00 A.M. what upper level electives are available ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program_course, semester WHERE course_offering.start_time > '21:00' AND course.course_id = course_offering.course_id AND program_course.category LIKE '%ULCS%' AND program_course.course_id = course.course_id AND semester.semester = 'Summer' AND semester.semester_id = course_offering.semester AND semester.year = 2017
### Instruction: have any microbiological tests been done on patient 031-3355's blood, venipuncture in the first hospital visit? ### Response:
SELECT COUNT(*) FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-3355' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND microlab.culturesite = 'blood, venipuncture'
### 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, 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 show in descending by the bar. ### Response:
SELECT JOB_ID, SUM(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY JOB_ID DESC
### Instruction: Does GREEKMOD 201 meet in the morning ? ### Response:
SELECT COUNT(*) > 0 FROM course, course_offering, semester WHERE course_offering.start_time < '12:00:00' AND course_offering.start_time >= '08:00:00' AND course.course_id = course_offering.course_id AND course.department = 'GREEKMOD' AND course.number = 201 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: count the number of times patient 1815 had a other brain dx procedure when they came to the hospital last time. ### 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 brain dx procedure') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 1815 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1)
### Instruction: Will SM 217 be offered every semester ? ### Response:
SELECT COUNT(*) > 0 FROM semester WHERE NOT semester IN (SELECT DISTINCT SEMESTERalias1.semester FROM course AS COURSEalias0, course_offering AS COURSE_OFFERINGalias0, semester AS SEMESTERalias1 WHERE COURSEalias0.course_id = COURSE_OFFERINGalias0.course_id AND COURSEalias0.department = 'SM' AND COURSEalias0.number = 217 AND SEMESTERalias1.semester_id = COURSE_OFFERINGalias0.semester)
### Instruction: has patient 013-33898 received a procedure of antihyperlipidemic agent - fenofibrate in 2105? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '013-33898')) AND treatment.treatmentname = 'antihyperlipidemic agent - fenofibrate' AND STRFTIME('%y', treatment.treatmenttime) = '2105'
### Instruction: Upvoted questions where all answers are downvoted. ### Response:
WITH cte AS (SELECT DISTINCT q.Id AS "post_link", COUNT(p.Id) OVER (PARTITION BY q.Id) AS "upvotedanswercount", COUNT(a.Id) OVER (PARTITION BY q.Id) AS totalAnswers, q.Score FROM Posts AS q LEFT JOIN Posts AS p ON q.Id = p.ParentId AND p.Score >= 0 INNER JOIN Posts AS a ON a.ParentId = q.Id WHERE q.Score >= 1) SELECT * FROM cte WHERE upvotedanswercount = 0 ORDER BY totalAnswers DESC
### Instruction: T-SQL example: find url w/ specific extension within a string. Finds a URL in a string based on the extension... Find the extension first (ie, 'GIF'), and then look in reverse for the prefix (ie, 'HTTP')... This way it will skip any prefixes from previous URL's in the string. ### Response:
SELECT STR_POSITION(@body, @strEnd) + LENGTH(@strStart) - (STR_POSITION(REVERSE(LEFT(@body, STR_POSITION(@body, @strEnd) + LENGTH(@strStart) - 1)), REVERSE(@strStart)) + LENGTH(@strStart) - 1)
### Instruction: What is the lowest group number that has a Fraction less than 0.000748, a Half-Life of 55.72 and a Decay Constant larger than 0.012400000000000001? ### Response:
SELECT MIN("Group") FROM table_68764 WHERE "Fraction" < '0.000748' AND "Half-Life (s)" = '55.72' AND "Decay Constant (s \u22121 )" > '0.012400000000000001'
### Instruction: when was the last time that patient 021-80293 had a minimum heartrate on the current icu visit? ### Response:
SELECT vitalperiodic.observationtime FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-80293') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.heartrate, vitalperiodic.observationtime DESC LIMIT 1
### Instruction: For the Fall and Winter , what upper-level electives are offered ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester INNER JOIN program_course ON program_course.course_id = course.course_id WHERE (semester.semester = 'FA' OR semester.semester = 'WN') AND course.department = 'EECS' AND program_course.category LIKE '%ULCS%' AND semester.year = 2016
### 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, give me the comparison about the average of manager_id over the job_id , and group by attribute job_id by a bar chart, could you order x axis in desc order? ### Response:
SELECT JOB_ID, AVG(MANAGER_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY JOB_ID DESC
### Instruction: until 4 years ago what were the five most commonly ordered drugs for patients of age 40s? ### Response:
SELECT t1.drug FROM (SELECT prescriptions.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.age BETWEEN 40 AND 49) AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-4 year') GROUP BY prescriptions.drug) AS t1 WHERE t1.c1 <= 5