instruction
stringlengths
57
490
output
stringlengths
69
1.29k
### Instruction: when is the first time patient 006-254182 was prescribed a medication via inpl route until 15 months ago? ### 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 = '006-254182')) AND medication.routeadmin = 'inpl' AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-15 month') ORDER BY medication.drugstarttime LIMIT 1
### Instruction: is the arterial bp mean of patient 5849 normal? ### Response:
SELECT COUNT(*) > 0 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 = 5849)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'arterial bp mean' AND d_items.linksto = 'chartevents') AND chartevents.valuenum BETWEEN mean_bp_lower AND mean_bp_upper
### Instruction: what is the average value of ptt in patient 55503's body in 11/last year? ### Response:
SELECT AVG(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 55503) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'ptt') AND DATETIME(labevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', labevents.charttime) = '11'
### Instruction: did patient 12410 excreted any urine out foley on the last icu visit? ### Response:
SELECT COUNT(*) > 0 FROM outputevents WHERE outputevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 12410) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime DESC LIMIT 1) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'urine out foley' AND d_items.linksto = 'outputevents')
### Instruction: what was the name of the last intake that patient 739 yesterday had? ### Response:
SELECT d_items.label FROM d_items WHERE d_items.itemid IN (SELECT inputevents_cv.itemid 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 = 739)) AND DATETIME(inputevents_cv.charttime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-1 day') ORDER BY inputevents_cv.charttime DESC LIMIT 1)
### Instruction: when was the last time patient 021-25705 has been diagnosed with depression since 2 years ago? ### Response:
SELECT diagnosis.diagnosistime FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-25705')) AND diagnosis.diagnosisname = 'depression' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-2 year') ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: Users Answer and Question Votes. See the total up and down votes for answers and questions for a given user. ### Response:
SELECT (CASE WHEN p.PostTypeId = 1 THEN 'Question' WHEN p.PostTypeId = 2 THEN 'Answer' END) AS "post_type", (CASE WHEN v.VoteTypeId = 2 THEN 'Up Vote' WHEN v.VoteTypeId = 3 THEN 'Down Vote' END) AS "vote_type", COUNT(*) AS Votes FROM Votes AS v JOIN Posts AS p ON v.PostId = p.Id WHERE v.VoteTypeId IN (2, 3) AND v.UserId = @userid GROUP BY p.PostTypeId, v.VoteTypeId
### Instruction: Top 100 posts with all comments upvoted. Inspired by this post: https://meta.stackexchange.com/questions/322566/say-to-the-new-contributor-that-upvoting-comments-does-almost-nothing-for-comm ### Response:
SELECT Posts.Id AS "post_link" FROM Posts, Comments WHERE Posts.PostTypeId = 1 AND Posts.CommentCount > 3 AND Posts.Id = Comments.PostId AND Posts.OwnerUserId != Comments.UserId GROUP BY Posts.Id HAVING MIN(Comments.Score) = 1 AND MAX(Comments.Score) = 1 LIMIT 100
### Instruction: Which courses are Dr. Karen Acton teaching next semester ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND instructor.name LIKE '%Karen Acton%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: had patient 027-165214 in 02/this year been allergic to any substance? ### Response:
SELECT COUNT(*) > 0 FROM allergy WHERE allergy.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '027-165214')) AND DATETIME(allergy.allergytime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', allergy.allergytime) = '02'
### Instruction: what was the last output that patient 23042 has had until 11/06/2104? ### Response:
SELECT d_items.label FROM d_items WHERE d_items.itemid IN (SELECT outputevents.itemid FROM outputevents WHERE outputevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 23042)) AND STRFTIME('%y-%m-%d', outputevents.charttime) <= '2104-11-06' ORDER BY outputevents.charttime DESC LIMIT 1)
### Instruction: what is the minimum hospital cost that includes a procedure known as hormonal therapy (for varices) since 3 years ago? ### Response:
SELECT MIN(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 = 'hormonal therapy (for varices)')) AND DATETIME(cost.chargetime) >= DATETIME(CURRENT_TIME(), '-3 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: when was the heartrate of patient 028-52605 last measured until 1060 days ago? ### 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 = '028-52605')) AND NOT vitalperiodic.heartrate IS NULL AND DATETIME(vitalperiodic.observationtime) <= DATETIME(CURRENT_TIME(), '-1060 day') ORDER BY vitalperiodic.observationtime DESC LIMIT 1
### Instruction: Does UKRAINE 252 only have sections before 10:00 , or are there any after ? ### 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 = 'UKRAINE' AND course.number = 252 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: Total Posts by Programming Languages Per Month - 2015. ### Response:
SELECT COUNT(*) AS PostCount, T.TagName, YEAR(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 YEAR(P.CreationDate) > 2014 AND P.CreationDate < '2015-12-01' AND NOT TagName LIKE '%rails%' GROUP BY YEAR(P.CreationDate), T.TagName HAVING COUNT(PostId) > 800 ORDER BY 2 DESC, 3 DESC, 1 DESC
### Instruction: TOP VBA PERFORMERS for date range. Top VBA/Excel Users for specified date range (or enter 0 in both for 'last 10 days with data'). Ranked by Overall: Sum of ( comments + score + (Answers * 2) ) ### Response:
SELECT c.UserId, COUNT(c.Id) AS qComments FROM Comments AS c JOIN Posts AS q ON c.PostId = q.Id WHERE c.CreationDate >= DATEADD(d, -10, (SELECT MAX(CreationDate) FROM Posts)) AND (q.Tags LIKE '%vba>%' OR q.Tags LIKE '%excel%') GROUP BY c.UserId ORDER BY COUNT(c.Id) DESC
### Instruction: retrieve patient ids of patients who are diagnosed with abn react-urinary cath in this year. ### 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 = 'abn react-urinary cath') AND DATETIME(diagnoses_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year'))
### Instruction: show the total amount of patient 011-29258's output until 08/17/2100. ### 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 = '011-29258')) AND intakeoutput.cellpath LIKE '%output%' AND STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime) <= '2100-08-17'
### Instruction: when is the first time that patient 028-11360 has had a sao2 measured on the last intensive care unit 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 = '028-11360') AND NOT patient.unitdischargetime IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1) AND NOT vitalperiodic.sao2 IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1
### Instruction: When are the COMPLIT 374 classes in the week . ### Response:
SELECT DISTINCT course_offering.friday, course_offering.monday, course_offering.saturday, course_offering.sunday, course_offering.thursday, course_offering.tuesday, course_offering.wednesday FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE course.department = 'COMPLIT' AND course.number = 374 ORDER BY semester.year DESC
### Instruction: Most popular data analysis languages by month and year. ### Response:
SELECT YEAR(Posts.CreationDate) AS year, MONTH(Posts.CreationDate) AS month, Tags.TagName AS language, COUNT(Tags.TagName) AS posts FROM Posts, Tags WHERE Tags.TagName IN ('r', 'python', 'java', 'stata', 'matlab', 'sas', 'tableau') AND Posts.Tags LIKE ('%<' + Tags.TagName + '>%') GROUP BY Tags.TagName, YEAR(Posts.CreationDate), MONTH(Posts.CreationDate) ORDER BY Tags.TagName, YEAR(Posts.CreationDate), MONTH(Posts.CreationDate)
### Instruction: tag answer count (2014 - today). ### Response:
SELECT t.TagName, t.Count AS tagCount, SUM(q.AnswerCount) AS answCnt FROM Posts AS q INNER JOIN Posts AS a ON q.AcceptedAnswerId = a.Id INNER JOIN PostTags AS pt ON pt.PostId = q.Id INNER JOIN Tags AS t ON pt.TagId = t.Id WHERE q.Id != a.Id AND q.OwnerUserId != a.OwnerUserId AND q.CreationDate >= '2014-01-01' AND q.PostTypeId = 1 AND a.PostTypeId = 2 GROUP BY t.TagName, t.Count ORDER BY answCnt DESC
### Instruction: count the number of patients who since 2105 had been diagnosed with adv eff sedat/hypnot nec. ### 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 = 'adv eff sedat/hypnot nec') AND STRFTIME('%y', diagnoses_icd.charttime) >= '2105')
### Instruction: What prerequisites do I need for EHS 616 and 615 ? ### Response:
SELECT DISTINCT COURSE_0.department, COURSE_0.name, COURSE_0.number FROM course AS COURSE_0, course AS COURSE_1, course_prerequisite WHERE (COURSE_1.number = 616 OR COURSE_1.number = 615) AND COURSE_0.course_id = course_prerequisite.pre_course_id AND COURSE_1.course_id = course_prerequisite.course_id AND COURSE_1.department = 'EHS'
### Instruction: what was the total number of outputs patient 56490 had on 09/10/last year? ### Response:
SELECT SUM(outputevents.value) FROM outputevents WHERE outputevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 56490)) AND DATETIME(outputevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m-%d', outputevents.charttime) = '09-10'
### Instruction: since 27 months ago what was the first time of patient 031-24513's microbiology test? ### Response:
SELECT microlab.culturetakentime FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-24513')) AND DATETIME(microlab.culturetakentime) >= DATETIME(CURRENT_TIME(), '-27 month') ORDER BY microlab.culturetakentime LIMIT 1
### Instruction: when did patient 030-28944 receive a test for creatinine for the last time this month? ### 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 = '030-28944')) AND lab.labname = 'creatinine' AND DATETIME(lab.labresulttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: votes on all posts by a specific user. ### Response:
SELECT pt.Name AS PostType, vt.Name AS VoteType, COUNT(v.Id) AS NumVotes FROM Posts AS p LEFT JOIN Votes AS v ON p.Id = v.PostId LEFT JOIN VoteTypes AS vt ON vt.Id = v.VoteTypeId LEFT JOIN PostTypes AS pt ON pt.Id = p.PostTypeId WHERE p.OwnerUserId = '##UserId##' AND p.DeletionDate IS NULL AND p.ClosedDate IS NULL GROUP BY pt.Name, vt.Name HAVING COUNT(v.Id) > 0 ORDER BY pt.Name DESC, vt.Name DESC
### 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: 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: when did patient 006-172277 get prescribed a drug via transdermal for the last time on the current hospital encounter? ### 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 = '006-172277' AND patient.hospitaldischargetime IS NULL)) AND medication.routeadmin = 'transdermal' ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: [points]+ rep users posted a [reaction] received answer during [last N months]. ### Response:
SELECT CAST(Posts.CreationDate AS DATE) AS PostDate, COUNT(DISTINCT Users.Id) AS UserCount FROM Users LEFT JOIN Posts ON Users.Id = Posts.OwnerUserId WHERE Users.Reputation >= 1e4 AND Users.LastAccessDate >= DATEADD(year, -1, GETDATE()) AND Posts.CreationDate >= DATEADD(year, -1, GETDATE()) AND Posts.PostTypeId = 2 AND Posts.Score >= 0 GROUP BY CAST(Posts.CreationDate AS DATE) ORDER BY PostDate
### Instruction: what is the name of the drug patient 002-67875 was first prescribed since 168 months ago? ### 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 = '002-67875')) AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-168 month') ORDER BY medication.drugstarttime LIMIT 1
### Instruction: what's the minimum cost of a hospital that includes a cortisol lab test until 4 years ago? ### Response:
SELECT MIN(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 = 'cortisol')) AND DATETIME(cost.chargetime) <= DATETIME(CURRENT_TIME(), '-4 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: Find posts in last 60 days with 'coreclr' in title, body or tags. ### Response:
SELECT Posts.Id AS "post_link", Title, Posts.CreationDate, PostTypeId, AnswerCount, Tags, ViewCount, Score, OwnerUserId AS "user_link", DisplayName, LastActivityDate, LastEditDate, ClosedDate, Body FROM Posts, Users WHERE Posts.OwnerUserId = Users.Id AND Posts.CreationDate >= CURRENT_TIMESTAMP() - 60 AND (Title LIKE '%coreclr%' OR Body LIKE '%coreclr%' OR Tags LIKE '%<coreclr>%')
### Instruction: Answer score badge acquisition for users with just one Nice-and-Great answer. ### Response:
SELECT U.Id AS "user_link" FROM Users AS U INNER JOIN Posts AS A ON A.OwnerUserId = U.Id INNER JOIN PostTags AS PT ON PT.PostId = A.Id INNER JOIN Tags AS T ON T.Id = PT.TagId INNER JOIN (SELECT OwnerUserId, MAX(Score) AS MaxScore FROM Posts WHERE PostTypeId = 2 AND Score >= 10 GROUP BY OwnerUserId) AS AC ON AC.OwnerUserId = U.Id WHERE T.TagName = '##TagName?haskell##'
### 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 amount of job_id over the job_id , and group by attribute job_id, and sort by the y axis in desc. ### Response:
SELECT JOB_ID, COUNT(JOB_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY COUNT(JOB_ID) DESC
### Instruction: what was the average value of patient 027-185580's triglycerides in the first hospital visit? ### Response:
SELECT AVG(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 = '027-185580' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND lab.labname = 'triglycerides'
### Instruction: what is the daily average of the weight of patient 016-38131 this month? ### Response:
SELECT AVG(patient.admissionweight) FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '016-38131') AND NOT patient.admissionweight IS NULL AND DATETIME(patient.unitadmittime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') GROUP BY STRFTIME('%y-%m-%d', patient.unitadmittime)
### Instruction: when was the first time that patient 031-1337 received a sputum, expectorated microbiology test? ### Response:
SELECT microlab.culturetakentime FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-1337')) AND microlab.culturesite = 'sputum, expectorated' ORDER BY microlab.culturetakentime LIMIT 1
### Instruction: tell me the maximum cost of a hospital if theophylline is involved until 2 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 lab.patientunitstayid FROM lab WHERE lab.labname = 'theophylline')) AND DATETIME(cost.chargetime) <= DATETIME(CURRENT_TIME(), '-2 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: when was the first blood culture - neonate microbiology test done for patient 72107 until 01/2104? ### Response:
SELECT microbiologyevents.charttime FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 72107) AND microbiologyevents.spec_type_desc = 'blood culture - neonate' AND STRFTIME('%y-%m', microbiologyevents.charttime) <= '2104-01' ORDER BY microbiologyevents.charttime LIMIT 1
### Instruction: what is the highest ANSI code with a latitude more than 47.623288 and a geo id more than 3805508060 with land (sqmi) more than 35.66 and a longitude less than -102.054248 ### Response:
SELECT MAX(ansi_code) FROM table_name_98 WHERE latitude > 47.623288 AND geo_id > 3805508060 AND land___sqmi__ > 35.66 AND longitude < -102.054248
### Instruction: Can the 300 -level classes be taken in the Spring or Summer term ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, semester.semester FROM course, course_offering, semester WHERE course.course_id = course_offering.course_id AND course.department = 'EECS' AND course.number BETWEEN 300 AND 300 + 100 AND semester.semester IN ('SP', 'SS', 'SU') AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: last time patient 018-20179 was diagnosed with coagulopathy - heparin administration? ### Response:
SELECT diagnosis.diagnosistime FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '018-20179')) AND diagnosis.diagnosisname = 'coagulopathy - heparin administration' ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: Can I take 611 and 539 as I need to leave for work at 5:00 everyday ? ### Response:
SELECT COUNT(*) = 0 FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE (course.number = 611 OR course.number = 539) AND course_offering.end_time > '17:00:00' AND semester.semester = 'WN' AND semester.year = 2016
### Instruction: In order to fulfill the PreMajor requirement which is the easiest class to take ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, program_course.workload, program_course.workload FROM course, program_course WHERE program_course.category LIKE '%PreMajor%' AND program_course.course_id = course.course_id AND program_course.workload = (SELECT MIN(PROGRAM_COURSEalias1.workload) FROM program_course AS PROGRAM_COURSEalias1 WHERE PROGRAM_COURSEalias1.category LIKE '%PreMajor%')
### Instruction: Can I leave at 5:00 P.M. every day if I take 370 and 489 ? ### Response:
SELECT COUNT(*) = 0 FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE (course.number = 370 OR course.number = 489) AND course_offering.end_time > '17:00:00' AND semester.semester = 'WN' AND semester.year = 2016
### Instruction: count the number of times that patient 70206 had received a alanine aminotransferase (alt) test in 2103? ### Response:
SELECT COUNT(*) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'alanine aminotransferase (alt)') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 70206) AND STRFTIME('%y', labevents.charttime) = '2103'
### Instruction: until 2104 what are the four most commonly ordered medications for patients of age 60 or above? ### Response:
SELECT t1.drugname FROM (SELECT medication.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age >= 60) AND STRFTIME('%y', medication.drugstarttime) <= '2104' GROUP BY medication.drugname) AS t1 WHERE t1.c1 <= 4
### Instruction: Is A History of Modern Psychology only taught by one person , Prof. Hull ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, instructor.name FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.name LIKE '%A History of Modern Psychology%' AND NOT instructor.name LIKE '%Hull%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: has quetiapine fumarate, phenylephrine, or ondansetron been prescribed until 05/2101 for patient 1372? ### 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 IN ('quetiapine fumarate', 'phenylephrine', 'ondansetron') AND STRFTIME('%y-%m', prescriptions.startdate) <= '2101-05'
### Instruction: what is the name of the drug patient 017-61209 was first prescribed during the first hospital visit? ### 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 = '017-61209' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) ORDER BY medication.drugstarttime LIMIT 1
### Instruction: what is patient 009-16880's last diagnosis on their first hospital visit? ### 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 = '009-16880' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: what exactly was the first drug that patient 10811 was prescribed in 02/last year? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 10811) AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', prescriptions.startdate) = '02' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: What is on offer in the way of hardware courses for Spring and Summer of 2019 ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, semester.semester FROM course INNER JOIN area ON course.course_id = area.course_id INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE area.area LIKE '%hardware%' AND semester.semester IN ('SP', 'SU', 'SS') AND semester.year = 2019
### Instruction: count the number of times that patient 17398 underwent a opn/oth rep mtrl vlv-tis procedure. ### 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 = 'opn/oth rep mtrl vlv-tis') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17398)
### Instruction: what was the total output of patient 59797's jp #2 medial? ### Response:
SELECT SUM(outputevents.value) FROM outputevents WHERE outputevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 59797)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'jp #2 medial' AND d_items.linksto = 'outputevents')
### Instruction: since 09/2104 has patient 005-87465 had a cortisol lab test? ### Response:
SELECT COUNT(*) > 0 FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '005-87465')) AND lab.labname = 'cortisol' AND STRFTIME('%y-%m', lab.labresulttime) >= '2104-09'
### Instruction: what is the average hospital cost that would involve a creatinine, pleural lab test in 2104? ### 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 = 'creatinine, pleural')) AND STRFTIME('%y', cost.chargetime) = '2104' GROUP BY cost.hadm_id) AS t1
### Instruction: WHAT WAS THE AMOUNT OF CARBON DIOXIDE EMISSIONS IN 2006 IN THE COUNTRY WHOSE CO2 EMISSIONS (TONS PER PERSON) REACHED 1.4 IN 2OO7? ### Response:
SELECT carbon_dioxide_emissions_per_year__10_6_tons___2006_ FROM table_11251601_2 WHERE carbon_dioxide_emissions_per_year__tons_per_person___2007_ = "1.4"
### Instruction: what is the yearly minimum of patient 006-14121's weight since 05/2105? ### Response:
SELECT MIN(patient.admissionweight) FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-14121') AND NOT patient.admissionweight IS NULL AND STRFTIME('%y-%m', patient.unitadmittime) >= '2105-05' GROUP BY STRFTIME('%y', patient.unitadmittime)
### Instruction: For Fall 2017 , is there a 1 -credit upper level class ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program_course, semester WHERE course.course_id = course_offering.course_id AND course.credits = 1 AND program_course.category LIKE '%ULCS%' AND program_course.course_id = course.course_id AND semester.semester = 'Fall' AND semester.semester_id = course_offering.semester AND semester.year = 2017
### Instruction: How many courses for each course description? Show me a stacked bar chart The x-axis is course description and group by instructor's name, and sort names in descending order. ### Response:
SELECT CRS_DESCRIPTION, COUNT(CRS_DESCRIPTION) 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 GROUP BY EMP_FNAME, CRS_DESCRIPTION ORDER BY CRS_DESCRIPTION DESC
### Instruction: what is the minimum cost in a hospital involving a laboratory test for lithium since 1 year ago? ### Response:
SELECT MIN(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 = 'lithium')) AND DATETIME(cost.chargetime) >= DATETIME(CURRENT_TIME(), '-1 year') GROUP BY cost.hadm_id) AS t1
### Instruction: is there any medication that has been prescribed to patient 016-6009 during the previous month? ### Response:
SELECT COUNT(*) > 0 FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '016-6009')) AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### Instruction: Bad question days by month. ### Response:
SELECT year_, month_, SUM(CASE WHEN down > 0 THEN 1 ELSE 0 END) AS bad_days FROM (SELECT YEAR(CreationDate) AS year_, MONTH(CreationDate) AS month_, MAX(CASE WHEN Score > 0 THEN 1 ELSE 0 END) AS up, MAX(CASE WHEN Score < 1 THEN 1 ELSE 0 END) AS down FROM Posts WHERE OwnerUserId = '##UserId##' AND PostTypeId = 1 GROUP BY CreationDate) AS question_days GROUP BY year_, month_ ORDER BY year_, month_
### Instruction: Closed Status of All Questions by Reputation. A graph what percentage of questions are closed, grouped by the reputation of the users who asked them. ### Response:
SELECT AVG(ROUND(Reputation, -1)) AS UserReputation, SUM(CASE WHEN ClosedDate IS NULL THEN 1 ELSE 0 END) / CAST(COUNT(Posts.Id) AS FLOAT) AS "PercentOpen" FROM Posts INNER JOIN Users ON (Users.Id = Posts.OwnerUserId) WHERE PostTypeId = 1 AND Reputation < 1000 GROUP BY ROUND(Reputation, -1) ORDER BY UserReputation
### Instruction: give me the total amount of patient 594's input on 05/10/2105? ### 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 = 594)) AND STRFTIME('%y-%m-%d', inputevents_cv.charttime) = '2105-05-10'
### Instruction: List the medicine name and trade name which can both interact as 'inhibitor' and 'activitor' with enzymes. ### Response:
SELECT T1.name, T1.trade_name FROM medicine AS T1 JOIN medicine_enzyme_interaction AS T2 ON T2.medicine_id = T1.id WHERE interaction_type = 'inhibitor' INTERSECT SELECT T1.name, T1.trade_name FROM medicine AS T1 JOIN medicine_enzyme_interaction AS T2 ON T2.medicine_id = T1.id WHERE interaction_type = 'activitor'
### Instruction: had patient 006-36108 during a month before been allergic to any substance? ### Response:
SELECT COUNT(*) > 0 FROM allergy WHERE allergy.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-36108')) AND DATETIME(allergy.allergytime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### 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 department_id bin hire_date by time, rank by the the average of department id from high to low. ### 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) ORDER BY AVG(DEPARTMENT_ID) 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, give me the trend about employee_id over hire_date , and could you order HIRE_DATE in descending order please? ### Response:
SELECT HIRE_DATE, EMPLOYEE_ID FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY HIRE_DATE DESC
### Instruction: How many answers are accepted?. ### Response:
SELECT COUNT(a.Id) AS "# answers", SUM(CASE WHEN q.AcceptedAnswerId = a.Id THEN 1 ELSE 0 END) AS "# accepted answers", CAST(1.0 * COUNT(q.AcceptedAnswerId) / COUNT(a.Id) AS FLOAT(3, 2)) AS "fraction accepted" FROM Posts AS q JOIN Posts AS a ON a.ParentId = q.Id JOIN Votes AS v ON v.PostId = a.Id WHERE q.PostTypeId = 1 AND v.VoteTypeId = 1
### Instruction: when they came to the hospital first time, glipizide, clonazepam or pantoprazole has been prescribed for patient 88404? ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 88404 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND prescriptions.drug IN ('glipizide', 'clonazepam', 'pantoprazole')
### Instruction: what is when they came to the hospital first time minimum albumin value of patient 029-584? ### 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 = '029-584' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND lab.labname = 'albumin'
### Instruction: what is the average macrophages value until 08/2104 for patient 1798? ### Response:
SELECT AVG(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 1798) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'macrophages') AND STRFTIME('%y-%m', labevents.charttime) <= '2104-08'
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, give me the comparison about the average of salary over the hire_date bin hire_date by time by a bar chart, and list by the mean salary from high to low please. ### Response:
SELECT HIRE_DATE, AVG(SALARY) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY AVG(SALARY) DESC
### 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 amount of hire_date bin hire_date by time in a bar chart, could you rank y axis from low to high order? ### Response:
SELECT HIRE_DATE, COUNT(HIRE_DATE) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY COUNT(HIRE_DATE)
### Instruction: Has LACS 400 ever been taught by Serena Ng ? ### Response:
SELECT COUNT(*) > 0 FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.department = 'LACS' AND course.number = 400 AND instructor.name LIKE '%Serena Ng%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: how many times do patient 378 get a anticardiolipin antibody igg test in the first hospital visit? ### Response:
SELECT COUNT(*) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'anticardiolipin antibody igg') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 378 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1)
### Instruction: What is the easiest class I can take to get the Core requirement ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, program_course.workload, program_course.workload FROM course, program_course WHERE program_course.category LIKE '%Core%' AND program_course.course_id = course.course_id AND program_course.workload = (SELECT MIN(PROGRAM_COURSEalias1.workload) FROM program_course AS PROGRAM_COURSEalias1 WHERE PROGRAM_COURSEalias1.category LIKE '%Core%')
### Instruction: tell me the name of the allergy patient 006-42293 has since 51 months ago? ### 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 = '006-42293')) AND DATETIME(allergy.allergytime) >= DATETIME(CURRENT_TIME(), '-51 month')
### Instruction: what was the name of the specimen test that patient 85895 has gotten the first the last month? ### Response:
SELECT microbiologyevents.spec_type_desc FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 85895) AND DATETIME(microbiologyevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY microbiologyevents.charttime LIMIT 1
### Instruction: Show Vote History for a Post. ### Response:
SELECT v.Id, v.PostId AS "post_link", v.UserId AS "user_link", v.CreationDate, v.BountyAmount, v.VoteTypeId, vt.Name FROM Posts AS p JOIN Votes AS v ON (p.Id = v.PostId) JOIN VoteTypes AS vt ON (v.VoteTypeId = vt.Id) WHERE p.Id = @PostId AND v.VoteTypeId IN (2, 3) ORDER BY v.CreationDate DESC
### Instruction: what was the dosage of ezetimibe that was last prescribed to patient 82159 during their last hospital encounter? ### Response:
SELECT prescriptions.dose_val_rx FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 82159 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND prescriptions.drug = 'ezetimibe' ORDER BY prescriptions.startdate DESC LIMIT 1