instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: how many times does patient 27463 get a e 24 fs po intake since 08/2103? ### Response:
SELECT COUNT(*) 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 = 27463)) AND inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'e 24 fs po' AND d_items.linksto = 'inputevents_cv') AND STRFTIME('%y-%m', inputevents_cv.charttime) >= '2103-08'
### Instruction: had any organism been found during the first sputum, expectorated microbiology test of patient 025-44495 since 32 months ago? ### Response:
SELECT COUNT(*) > 0 FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '025-44495')) AND microlab.culturesite = 'sputum, expectorated' AND DATETIME(microlab.culturetakentime) >= DATETIME(CURRENT_TIME(), '-32 month') ORDER BY microlab.culturetakentime LIMIT 1
### Instruction: Get questioners and answerers for specific tag. ### Response:
SELECT p.Id, p.CreationDate, p.Score, p.ViewCount, p.Title, p.AnswerCount, p.CommentCount, p.FavoriteCount, u.DisplayName AS quest_name, u.Reputation AS quest_rep, u2.DisplayName AS ans_name, u2.Reputation AS ans_rep FROM Posts AS p JOIN PostTags AS pt ON p.Id = pt.PostId JOIN Tags AS t ON pt.TagId = t.Id LEFT JOIN Posts AS ans ON p.AcceptedAnswerId = ans.Id LEFT JOIN Users AS u ON p.OwnerUserId = u.Id LEFT JOIN Users AS u2 ON ans.OwnerUserId = u2.Id WHERE t.TagName = 'facebook-graph-api'
### Instruction: what is the percentile of 1.8 for a creatinine lab test given the same age as patient 021-79544 during the first hospital visit? ### Response:
SELECT DISTINCT t1.c1 FROM (SELECT lab.labresult, PERCENT_RANK() OVER (ORDER BY lab.labresult) AS c1 FROM lab WHERE lab.labname = 'creatinine' AND lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age = (SELECT patient.age FROM patient WHERE patient.uniquepid = '021-79544' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1))) AS t1 WHERE t1.labresult = 1.8
### Instruction: Get python+regex questions, searching for non-regex answers. ### Response:
SELECT q.Id AS question_id, q.Title AS question_title, q.CreationDate AS question_date, a.Id AS answer_id, q.Tags AS question_tags, q.OwnerUserId AS question_user_id, q.OwnerDisplayName AS question_user_name, a.OwnerUserId AS answer_user_id, a.OwnerDisplayName AS answer_user_name, a.Score AS answer_score, q.Score AS question_score, q.ViewCount AS question_view_count FROM Posts AS q INNER JOIN Posts AS a ON a.ParentId = q.Id WHERE q.Tags LIKE ('%python%') AND q.Tags LIKE ('%<regex>%') AND q.PostTypeId = 1
### Instruction: What kind of brakes for the model type rb 4at with 16x8.0jj (front) 16x8.0jj (rear) wheels and 225/50r16 92v(front) 225/50r16 92v(rear) tyres? ### Response:
SELECT "Brakes" FROM table_27284 WHERE "Wheels" = '16x8.0JJ (front) 16x8.0JJ (rear)' AND "Tyres" = '225/50R16 92V(front) 225/50R16 92V(rear)' AND "Model" = 'Type RB 4AT'
### Instruction: how much patient 14203 weighs during the first hospital encounter for the first time. ### 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 = 14203 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'admit wt' AND d_items.linksto = 'chartevents') ORDER BY chartevents.charttime LIMIT 1
### Instruction: since 02/01/2102, list the monthly minimum sao2 of patient 018-81471. ### Response:
SELECT MIN(vitalperiodic.sao2) FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '018-81471')) AND NOT vitalperiodic.sao2 IS NULL AND STRFTIME('%y-%m-%d', vitalperiodic.observationtime) >= '2102-02-01' GROUP BY STRFTIME('%y-%m', vitalperiodic.observationtime)
### Instruction: how many hours have it been since patient 005-4471 received a antibacterials - vancomycin for the first time in this 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 = '005-4471' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'antibacterials - vancomycin' ORDER BY treatment.treatmenttime LIMIT 1
### Instruction: give me the CO flights from SEATTLE ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE (CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SEATTLE' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND flight.airline_code = 'CO'
### Instruction: Find Question with Specific Tag, Title and Answer Text. ### Response:
SELECT P.Id AS "post_link", P.Tags FROM Posts AS P, PostTags AS Pt, Tags AS T WHERE P.Id = Pt.PostId AND T.Id = Pt.TagId AND T.TagName = '##tag1##' AND P.Title LIKE '%##titleText##%' AND P.PostTypeId = 1 AND P.AnswerCount > 0 AND NOT P.AcceptedAnswerId IS NULL AND NOT (SELECT P2.Id FROM Posts AS P2 WHERE P2.Id = P.AcceptedAnswerId AND P2.Body LIKE '%##answerText##%') IS NULL AND (SELECT COUNT(Pt.TagId) FROM PostTags AS Pt WHERE Pt.PostId = P.Id) = 1
### Instruction: Are there multiple professors who teach ECON 631 in Spring-Summer 2003 ? ### Response:
SELECT COUNT(DISTINCT instructor.instructor_id) FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND course.department = 'ECON' AND course.number = 631 AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'Spring-Summer' AND semester.semester_id = course_offering.semester AND semester.year = 2003
### Instruction: when was the last time that patient 49036 received a procedure of sm bowel endoscopy nec until 2104? ### Response:
SELECT procedures_icd.charttime FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'sm bowel endoscopy nec') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 49036) AND STRFTIME('%y', procedures_icd.charttime) <= '2104' ORDER BY procedures_icd.charttime DESC LIMIT 1
### Instruction: what was the minimum daily number of patients who had malig neo bladder nec until 2 years ago? ### Response:
SELECT MIN(t1.c1) FROM (SELECT COUNT(DISTINCT diagnoses_icd.hadm_id) AS c1 FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'malig neo bladder nec') AND DATETIME(diagnoses_icd.charttime) <= DATETIME(CURRENT_TIME(), '-2 year') GROUP BY STRFTIME('%y-%m-%d', diagnoses_icd.charttime)) AS t1
### Instruction: The easiest of all of the Core courses is taught by whom ? ### Response:
SELECT DISTINCT instructor.name, program_course.workload 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 program_course ON program_course.course_id = course_offering.course_id WHERE program_course.category LIKE '%Core%' AND program_course.workload = (SELECT MIN(PROGRAM_COURSEalias1.workload) FROM program_course AS PROGRAM_COURSEalias1 WHERE PROGRAM_COURSEalias1.category LIKE '%Core%')
### Instruction: how many patients whose ethnicity is hispanic/latino - puerto rican and diagnoses long title is closed fracture of base of skull with subarachnoid, subdural, and extradural hemorrhage, with loss of consciousness of unspecified duration? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.ethnicity = "HISPANIC/LATINO - PUERTO RICAN" AND diagnoses.long_title = "Closed fracture of base of skull with subarachnoid, subdural, and extradural hemorrhage, with loss of consciousness of unspecified duration"
### Instruction: how much did patient 19144 weigh last measured in their first hospital visit? ### 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 = 19144 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'admit wt' AND d_items.linksto = 'chartevents') ORDER BY chartevents.charttime DESC LIMIT 1
### Instruction: what is the drug that patient 006-71495 was prescribed two or more times until 46 months ago? ### Response:
SELECT t1.drugname FROM (SELECT medication.drugname, COUNT(medication.drugstarttime) AS c1 FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-71495')) AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-46 month') GROUP BY medication.drugname) AS t1 WHERE t1.c1 >= 2
### Instruction: when is the last sputum, tracheal specimen microbiological test on patient 025-44495 during the last hospital encounter? ### 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 = '025-44495' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND microlab.culturesite = 'sputum, tracheal specimen' ORDER BY microlab.culturetakentime DESC LIMIT 1
### Instruction: Frequency of anonymous suggested edits. Returns the cumulative number of suggested edits that were submitted by anonymous users over the past NumberOfEdits suggested edits. If the anonymous suggestion rate was constant at x%, then the graph would show a straight line at slope 100x (e.g. if all edit suggestions were anonymous, a straight line with slope 1). ### Response:
SELECT 'post_link', Score, NumEdits FROM (SELECT p.Id AS "post_link", p.Score AS Score, COUNT(ph.UserId) AS NumEdits FROM Posts AS p, PostHistory AS ph WHERE p.Id = ph.PostId AND p.Score >= 100 AND ph.UserId != p.OwnerUserId GROUP BY p.Id, p.Score) AS Y WHERE NumEdits >= 10
### Instruction: until 1 year ago what was the first procedure time of muscle or fascia graft for patient 19352? ### Response:
SELECT procedures_icd.charttime FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'muscle or fascia graft') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 19352) AND DATETIME(procedures_icd.charttime) <= DATETIME(CURRENT_TIME(), '-1 year') ORDER BY procedures_icd.charttime LIMIT 1
### Instruction: What is the number of professors teaching RACKHAM 571 in Winter 2020 ? ### Response:
SELECT COUNT(DISTINCT instructor.instructor_id) FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND course.department = 'RACKHAM' AND course.number = 571 AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'Winter' AND semester.semester_id = course_offering.semester AND semester.year = 2020
### Instruction: what is the percentile value of magnesium 2.2 among patients of the same age as patient 016-6134 on the last hospital encounter? ### Response:
SELECT DISTINCT t1.c1 FROM (SELECT lab.labresult, PERCENT_RANK() OVER (ORDER BY lab.labresult) AS c1 FROM lab WHERE lab.labname = 'magnesium' AND lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age = (SELECT patient.age FROM patient WHERE patient.uniquepid = '016-6134' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1))) AS t1 WHERE t1.labresult = 2.2
### Instruction: what was the total amount of gastric tube production that patient 55281 had had during the previous day? ### 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 = 55281)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'gastric tube' AND d_items.linksto = 'outputevents') AND DATETIME(outputevents.charttime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-1 day')
### Instruction: has patient 005-87465 received oxygen therapy (> 60%) - >90% since 2105 in another hospital? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.uniquepid = '005-87465' AND patient.hospitalid <> (SELECT DISTINCT patient.hospitalid FROM patient WHERE patient.uniquepid = '005-87465' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'oxygen therapy (> 60%) - >90%' AND STRFTIME('%y', treatment.treatmenttime) >= '2105'
### Instruction: when was patient 004-11043 diagnosed with drug overdose- general - multiple agents ingested for the first time until 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 = '004-11043')) AND diagnosis.diagnosisname = 'drug overdose- general - multiple agents ingested' AND DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-2 year') ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: how many days have it been since patient 035-24054 had the last schizophrenia diagnosis during the current hospital visit? ### Response:
SELECT 1 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', 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 = '035-24054' AND patient.hospitaldischargetime IS NULL)) AND diagnosis.diagnosisname = 'schizophrenia' ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: when did patient 16368 last got the maximum of arterial bp [diastolic]? ### Response:
SELECT chartevents.charttime 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 = 16368)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'arterial bp [diastolic]' AND d_items.linksto = 'chartevents') ORDER BY chartevents.valuenum DESC, chartevents.charttime DESC LIMIT 1
### Instruction: when was the first time in 12/this year that patient 015-59552 was prescribed for a medication? ### 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 = '015-59552')) AND DATETIME(medication.drugstarttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', medication.drugstarttime) = '12' ORDER BY medication.drugstarttime LIMIT 1
### Instruction: what percentile is the value of the pt of 17.4 among patients of the same age as patient 011-14590 during the first hospital visit? ### Response:
SELECT DISTINCT t1.c1 FROM (SELECT lab.labresult, PERCENT_RANK() OVER (ORDER BY lab.labresult) AS c1 FROM lab WHERE lab.labname = 'pt' AND lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age = (SELECT patient.age FROM patient WHERE patient.uniquepid = '011-14590' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1))) AS t1 WHERE t1.labresult = 17.4
### Instruction: Low views, high votes com os comentarios de 2017. ### Response:
SELECT questao.Id AS "post_link", questao.Score, questao.Title, questao.Body, questao.Tags, questao.ViewCount, comentario.Id, comentario.Score AS socre_comentario, comentario.ViewCount AS views_comentario FROM Posts AS questao JOIN Posts AS comentario ON questao.Id = comentario.ParentId WHERE questao.Tags LIKE '%<windows-phone%' AND questao.CreationDate BETWEEN '01/01/2017' AND '12/31/2017' AND questao.ParentId IS NULL ORDER BY comentario.Score DESC, questao.ViewCount
### Instruction: What classes has Dr. Stephen Miller taught in the past ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor WHERE course_offering.semester < (SELECT SEMESTERalias0.semester_id FROM semester AS SEMESTERalias0 WHERE SEMESTERalias0.semester = 'WN' AND SEMESTERalias0.year = 2016) AND course.course_id = course_offering.course_id AND instructor.name LIKE '%Stephen Miller%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: what ground transportation is available from the PITTSBURGH airport to downtown and how much does it cost ### Response:
SELECT DISTINCT ground_service.ground_fare, ground_service.transport_type FROM airport, airport_service, city AS CITY_0, city AS CITY_1, ground_service WHERE airport.airport_code = airport_service.airport_code AND CITY_0.city_code = airport_service.city_code AND CITY_0.city_name = 'PITTSBURGH' AND CITY_1.city_name = 'PITTSBURGH' AND ground_service.airport_code = airport.airport_code AND ground_service.city_code = CITY_1.city_code
### Instruction: High rep users with low score answers. A query to look for possible hidden gems listing low score answers from high rep users. ### Response:
SELECT u.Id AS "user_link", a.Id AS "post_link", a.CreationDate, q.Tags FROM Posts AS a JOIN Users AS u ON a.OwnerUserId = u.Id JOIN (SELECT q.Id, q.Tags, MAX(a.Score) AS MaxAnswerScore FROM Posts AS q JOIN Posts AS a ON a.ParentId = q.Id WHERE q.AcceptedAnswerId IS NULL GROUP BY q.Id, q.Tags) AS q ON a.ParentId = q.Id WHERE (u.Reputation > @reputationLimit) AND a.Score <= @lowScoreLimit ORDER BY a.Score, a.CreationDate LIMIT 100
### Instruction: what was the name of drug that was prescribed first to patient 021-111547 in 12/this year? ### 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 = '021-111547')) AND DATETIME(medication.drugstarttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', medication.drugstarttime) = '12' ORDER BY medication.drugstarttime LIMIT 1
### Instruction: what's the first heart rate of patient 2004 on the first intensive care unit visit? ### 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 = 2004) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime LIMIT 1) 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 LIMIT 1
### Instruction: what is the number of times patient 008-40862 had a volume (ml) furosemide intake on 06/29/2105? ### Response:
SELECT COUNT(*) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '008-40862')) AND intakeoutput.cellpath LIKE '%intake%' AND intakeoutput.celllabel = 'volume (ml) furosemide' AND STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime) = '2105-06-29'
### Instruction: how many patients had d & c nec procedure two times until 2 years ago? ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, COUNT(*) AS c1 FROM procedures_icd JOIN admissions ON procedures_icd.hadm_id = admissions.hadm_id WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'd & c nec') AND DATETIME(procedures_icd.charttime) <= DATETIME(CURRENT_TIME(), '-2 year') GROUP BY admissions.subject_id) AS t1 WHERE t1.c1 = 2
### Instruction: was ecotrin, furosemide inj, or vitamins/minerals po tabs prescribed for patient 035-17122 since 154 months ago? ### 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 = '035-17122')) AND medication.drugname IN ('furosemide inj', 'vitamins/minerals po tabs', 'ecotrin') AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-154 month')
### Instruction: so how many days have passed since patient 002-34744's last depression - mild diagnosis during their current hospital visit? ### Response:
SELECT 1 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', 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 = '002-34744' AND patient.hospitaldischargetime IS NULL)) AND diagnosis.diagnosisname = 'depression - mild' ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: Users with highest percentage of approved edits. ### Response:
WITH perc_cte AS (SELECT OwnerUserId AS uid, COUNT(Id) AS Total, COUNT(ApprovalDate) AS Approved, COUNT(RejectionDate) AS Rejected, ROUND((COUNT(ApprovalDate)) * 100.0 / (COUNT(Id)), 2) AS PercApproved, ROUND((COUNT(RejectionDate)) * 100.0 / (COUNT(Id)), 2) AS PercRejected FROM SuggestedEdits GROUP BY OwnerUserId) SELECT uid AS "user_link", PercApproved, PercRejected, Approved, Rejected, Total FROM perc_cte ORDER BY PercApproved DESC LIMIT 100
### Instruction: what was the last time of intake of patient 27362 on 06/09/last year? ### Response:
SELECT inputevents_cv.charttime 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 = 27362)) AND DATETIME(inputevents_cv.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m-%d', inputevents_cv.charttime) = '06-09' ORDER BY inputevents_cv.charttime DESC LIMIT 1
### Instruction: Mean time in minutes between Q posted and accepted A posted. ### Response:
SELECT DISTINCT T.TagName, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY CAST((JULIANDAY(CreationDate) - JULIANDAY(Q.CreationDate)) * 1440.0 AS INT)) OVER (PARTITION BY T.TagName) AS Minutes FROM Posts AS Q INNER JOIN Posts AS A ON A.Id = Q.AcceptedAnswerId INNER JOIN (VALUES ('sql-server'), ('oracle'), ('ssis'), ('db2'), ('mysql'), ('postgresql'), ('mongodb')) AS T(TagName) ON Q.Tags LIKE '%' + T.TagName + '%' WHERE Q.CreationDate >= @FromDate AND Q.CreationDate < @ToDate
### Instruction: Estimated creation timestamps of the votes on your posts. Its precision is around a minute on the SO. You need to use your SE Account Id, not your site account id! ### Response:
WITH PhRaw AS (SELECT Id, PostId, PostHistoryTypeId, CreationDate, DATEFROMPARTS(TIME_TO_STR(CreationDate, '%Y'), TIME_TO_STR(CreationDate, '%M'), TIME_TO_STR(CreationDate, '%-d')) AS Day FROM PostHistory WHERE PostHistoryTypeId IN (10, 11, 12, 13)), PhRawMaxId AS (SELECT MAX(Id) AS LastId FROM PhRaw GROUP BY PostId, PostHistoryTypeId, Day) SELECT * FROM PhRaw WHERE Id IN (SELECT LastId FROM PhRawMaxId)
### Instruction: how many patients was given lap gastric restric proc in 2101 for two times? ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, COUNT(*) AS c1 FROM procedures_icd JOIN admissions ON procedures_icd.hadm_id = admissions.hadm_id WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'lap gastric restric proc') AND STRFTIME('%y', procedures_icd.charttime) = '2101' GROUP BY admissions.subject_id) AS t1 WHERE t1.c1 = 2
### Instruction: Stats for tags per days #1. ### Response:
SELECT DATE(CreationDate) AS post_date, Tags, SUM(Score) AS score_sum, SUM(ViewCount) AS views, SUM(AnswerCount) AS answers, SUM(FavoriteCount) AS favorites, SUM(CommentCount) AS comments, COUNT(1) AS usage_cnt FROM Posts WHERE Tags IN ('<r>', '<python>', '<java>', '<scala>', '<ruby>', '<c>', '<c++>', '<c#>', '<spark>', '<hadoop>', '<sql>') AND DATE(CreationDate) BETWEEN '2006-01-01' AND '2017-12-31' AND PostTypeId = 1 GROUP BY DATE(CreationDate), Tags
### Instruction: when was patient 12572 since 4 years ago last diagnosed with ileostomy status? ### Response:
SELECT diagnoses_icd.charttime FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'ileostomy status') AND diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 12572) AND DATETIME(diagnoses_icd.charttime) >= DATETIME(CURRENT_TIME(), '-4 year') ORDER BY diagnoses_icd.charttime DESC LIMIT 1
### Instruction: In Summer of 2009 , how many professors taught CHEMBIO 502 ? ### Response:
SELECT COUNT(DISTINCT instructor.instructor_id) FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND course.department = 'CHEMBIO' AND course.number = 502 AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'Summer' AND semester.semester_id = course_offering.semester AND semester.year = 2009
### Instruction: how many patients underwent a packed cell transfusion two times since 2104? ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, COUNT(*) AS c1 FROM procedures_icd JOIN admissions ON procedures_icd.hadm_id = admissions.hadm_id WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'packed cell transfusion') AND STRFTIME('%y', procedures_icd.charttime) >= '2104' GROUP BY admissions.subject_id) AS t1 WHERE t1.c1 = 2
### Instruction: tags distribution on the major legal tags non-legal related. ### Response:
SELECT t.TagName, COUNT(*) AS "number_of_question" FROM PostTags AS pt INNER JOIN PostTags AS bpt ON pt.PostId = bpt.PostId INNER JOIN Tags AS bt ON bt.Id = bpt.TagId INNER JOIN Tags AS t ON t.Id = pt.TagId AND t.Id != bt.Id WHERE bt.TagName = '##tag##' AND t.TagName NOT IN ('licensing', 'gpl', 'open-source', 'lgpl', 'legal', 'mit-license', 'apache-license', 'commercial', 'gplv3', 'license-key', 'bsd-license') GROUP BY t.TagName ORDER BY COUNT(*) DESC LIMIT 100
### Instruction: when patient 018-95228 was prescribed albumin 5% 500 ml inj last time since 141 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 = '018-95228')) AND medication.drugname = 'albumin 5% 500 ml inj' AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-141 month') ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: Do you know who is the MDE classes teacher next Winter ? ### Response:
SELECT DISTINCT instructor.name 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_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 program_course.category LIKE '%MDE%' AND semester.semester = 'Winter' AND semester.year = 2017
### Instruction: what was the total output that patient 006-80884 had on this month/22? ### 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-80884')) AND intakeoutput.cellpath LIKE '%output%' AND DATETIME(intakeoutput.intakeoutputtime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') AND STRFTIME('%d', intakeoutput.intakeoutputtime) = '22'
### Instruction: what were the names of the output that patient 43779 had first on this month/15? ### 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 = 43779)) AND DATETIME(outputevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') AND STRFTIME('%d', outputevents.charttime) = '15' ORDER BY outputevents.charttime LIMIT 1)
### Instruction: Dr. Kenneth Garner taught which classes ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor WHERE course_offering.semester < (SELECT SEMESTERalias0.semester_id FROM semester AS SEMESTERalias0 WHERE SEMESTERalias0.semester = 'WN' AND SEMESTERalias0.year = 2016) AND course.course_id = course_offering.course_id AND instructor.name LIKE '%Kenneth Garner%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: number the number of times patient 27703 had been given or ffp during a month before. ### Response:
SELECT COUNT(*) 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 = 27703)) AND inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'or ffp' AND d_items.linksto = 'inputevents_cv') AND DATETIME(inputevents_cv.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### Instruction: DENVER to ATLANTA ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DENVER' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ATLANTA' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Questions bookmarked or commented on by user. ### Response:
SELECT q.Id AS "post_link", q.CreationDate, q.Score, q.Tags, b.CreationDate AS "Bookmark date", c.CreationDate AS "Comment date", c.Id AS "comment_link" FROM Posts AS q LEFT OUTER JOIN Votes AS b ON q.Id = b.PostId AND b.VoteTypeId = 5 AND b.UserId = '##UserId:int##' LEFT JOIN LATERAL (SELECT Id, CreationDate FROM Comments WHERE PostId = q.Id AND UserId = '##UserId:int##' ORDER BY CreationDate LIMIT 1) AS c WHERE NOT b.Id IS NULL OR NOT c.Id IS NULL ORDER BY q.CreationDate DESC
### Instruction: Search for answers by user to questions closed as duplicates. ### Response:
SELECT question.Id AS "post_link", answers.CreationDate, answers.Id AS "post_link", ph.CreationDate AS Closed, answers.OwnerUserId AS "user_link", cr.Name FROM Posts AS answers INNER JOIN Posts AS question ON question.Id = answers.ParentId INNER JOIN PostHistory AS ph ON ph.PostId = question.Id INNER JOIN CloseReasonTypes AS cr ON cr.Id = ph.Comment WHERE answers.OwnerUserId = '##UserId##' AND answers.PostTypeId = 2 AND NOT question.ClosedDate IS NULL AND ph.PostHistoryTypeId = 10 AND (ph.Comment LIKE '1' OR ph.Comment LIKE '101') ORDER BY answers.CreationDate DESC
### Instruction: what was the name of the procedure that until 18 months ago patient 005-16601 has received two times? ### Response:
SELECT t1.treatmentname FROM (SELECT treatment.treatmentname, COUNT(treatment.treatmenttime) AS c1 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '005-16601')) AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-18 month') GROUP BY treatment.treatmentname) AS t1 WHERE t1.c1 = 2
### Instruction: how many hours was it since patient 006-14121's last sepsis - severe diagnosis during this hospital visit. ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', 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 = '006-14121' AND patient.hospitaldischargetime IS NULL)) AND diagnosis.diagnosisname = 'sepsis - severe' ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: Users who have python + ios tags under age of 20. ### Response:
SELECT DISTINCT (DisplayName), Location, CONCAT(AboutMe, WebsiteUrl), Reputation, CONCAT('http://stackoverflow.com/users/', Users.Id) FROM Users INNER JOIN Posts ON Posts.OwnerUserId = Users.Id INNER JOIN PostTags ON (Posts.Id = PostTags.PostId) WHERE PostTags.TagId IN (SELECT Id FROM Tags WHERE TagName = 'ios') AND Users.Id IN (SELECT Users.Id FROM Users INNER JOIN Posts ON Posts.OwnerUserId = Users.Id INNER JOIN PostTags ON (Posts.Id = PostTags.PostId) WHERE PostTags.TagId IN (SELECT Id FROM Tags WHERE TagName = 'python')) AND age < 20 ORDER BY Reputation DESC
### Instruction: how many hours have there been since patient 033-22108 received his last morphine sulfate prescription on the current hospital encounter? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', 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 = '033-22108') AND patient.hospitaldischargetime IS NULL) AND medication.drugname = 'morphine sulfate' ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: List the prerequisites I 've finished for GREEKMOD 501 . ### Response:
SELECT DISTINCT COURSE_0.department, COURSE_0.name, COURSE_0.number FROM course AS COURSE_0, course AS COURSE_1, course_prerequisite, student_record WHERE COURSE_0.course_id = course_prerequisite.pre_course_id AND COURSE_1.course_id = course_prerequisite.course_id AND COURSE_1.department = 'GREEKMOD' AND COURSE_1.number = 501 AND student_record.course_id = COURSE_0.course_id AND student_record.student_id = 1
### Instruction: PHOENIX to DENVER ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PHOENIX' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DENVER' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Unanswered questions in a tag by asker reputation. Find unanswered questions in a tag by asker reputation ### Response:
SELECT Posts.Id AS "post_link", Posts.Tags AS "tags", Posts.Score, Posts.ViewCount, Posts.CreationDate, Users.LastAccessDate FROM Posts INNER JOIN PostTags ON Posts.Id = PostTags.PostId INNER JOIN Tags ON PostTags.TagId = Tags.Id INNER JOIN Users ON Posts.OwnerUserId = Users.Id WHERE Tags.TagName = '##TagName##' AND Posts.AnswerCount = 0 AND Posts.PostTypeId = 1 AND Posts.CommunityOwnedDate IS NULL AND Posts.ClosedDate IS NULL AND Users.Reputation > 500 ORDER BY Users.LastAccessDate DESC
### Instruction: what's the number of patients who had a d5w w/20gm cagluc intake since 2105? ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT icustays.hadm_id FROM icustays WHERE icustays.icustay_id IN (SELECT inputevents_cv.icustay_id FROM inputevents_cv WHERE inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'd5w w/20gm cagluc' AND d_items.linksto = 'inputevents_cv') AND STRFTIME('%y', inputevents_cv.charttime) >= '2105'))
### Instruction: how many times since 02/2105 have patient 20603's had a tube feeding intake? ### Response:
SELECT COUNT(*) 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 = 20603)) AND inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'tube feeding' AND d_items.linksto = 'inputevents_cv') AND STRFTIME('%y-%m', inputevents_cv.charttime) >= '2105-02'
### Instruction: counts the number of times patient 73713 received a coronar arteriogr-2 cath procedure this year. ### 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 = 'coronar arteriogr-2 cath') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 73713) AND DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')
### Instruction: What has Dr. Eugene Anderson taught previously ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor WHERE course_offering.semester < (SELECT SEMESTERalias0.semester_id FROM semester AS SEMESTERalias0 WHERE SEMESTERalias0.semester = 'WN' AND SEMESTERalias0.year = 2016) AND course.course_id = course_offering.course_id AND instructor.name LIKE '%Eugene Anderson%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: Tags assoc. with users with answered questions. ### Response:
WITH P AS (SELECT ParentId, Id, OwnerUserId, CASE WHEN PostTypeId = 1 THEN Id WHEN PostTypeId = 2 THEN ParentId END AS PID FROM Posts WHERE OwnerUserId IN (SELECT OwnerUserId FROM Posts WHERE Id IN (SELECT P1.AcceptedAnswerId FROM Posts AS P1 WHERE P1.PostTypeId = 1 AND NOT P1.AcceptedAnswerId IS NULL))) SELECT P.PID, Posts.OwnerUserId, T.TagName, Posts.CreationDate FROM P INNER JOIN Posts ON P.PID = Posts.Id INNER JOIN PostTags AS PT ON PT.PostId = P.PID INNER JOIN Tags AS T ON T.Id = PT.TagId
### Instruction: what is the name of a drug that patient 033-250 has been prescribed for two times until 13 months ago? ### Response:
SELECT t1.drugname FROM (SELECT medication.drugname, COUNT(medication.drugstarttime) AS c1 FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '033-250')) AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-13 month') GROUP BY medication.drugname) AS t1 WHERE t1.c1 = 2
### Instruction: did patient 63676 undergo a opn reduct malar/zygo fx procedure during this year? ### 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 = 'opn reduct malar/zygo fx') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 63676) AND DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')
### Instruction: tell me the maximum hospital cost that involves a non-cardiac angiography - cerebral arteriogram procedure in 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 treatment.patientunitstayid FROM treatment WHERE treatment.treatmentname = 'non-cardiac angiography - cerebral arteriogram')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: what was the first bronchial lavage microbiology test performed until 36 months ago for patient 031-19622? ### 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-19622')) AND microlab.culturesite = 'bronchial lavage' AND DATETIME(microlab.culturetakentime) <= DATETIME(CURRENT_TIME(), '-36 month') ORDER BY microlab.culturetakentime LIMIT 1
### Instruction: Questions with 'n' tags: [homework], [CHOOSE YOUR OWN ADVENTURE], and n-2 others. ### Response:
SELECT q.Id AS "post_link", q.Score, q.Tags, q.ClosedDate FROM Posts AS q WHERE q.PostTypeId = 1 AND q.Tags LIKE '%<homework>%' AND q.Tags LIKE '%<' + @CoTag + '>%' AND LENGTH(q.Tags) - LENGTH(REPLACE(q.Tags, '><', '')) = 2 * (@NumTags - 1) AND ((q.ClosedDate IS NULL AND UPPER(@OpenQs) = 'Y') OR (NOT q.ClosedDate IS NULL AND UPPER(@ClosedQs) = 'Y'))
### Instruction: how many days has elapsed since patient 012-20116 was given a insulin - continuous infusion procedure for the first time on the current hospital encounter? ### 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 = '012-20116' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'insulin - continuous infusion' ORDER BY treatment.treatmenttime LIMIT 1
### Instruction: when was patient 006-195310 diagnosed with leukemia - acute lymphocytic the last time since 2101? ### 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 = '006-195310')) AND diagnosis.diagnosisname = 'leukemia - acute lymphocytic' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2101' ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: Threads with the largest number of comments. ### Response:
SELECT COALESCE(p.ParentId, p.Id) AS "post_link", SUM(p.CommentCount) AS "#comments", MAX(CASE p.PostTypeId WHEN 1 THEN p.CommentCount ELSE 0 END) AS "#q_com", MAX(p.AnswerCount) AS "#ans", MAX(p.ViewCount) AS "views", MAX(CASE p.PostTypeId WHEN 1 THEN p.Score ELSE -32767 END) AS "q_score", SUM(p.Score) AS "total_score", MIN(p.CreationDate) AS "q_date" FROM Posts AS p GROUP BY COALESCE(p.ParentId, p.Id) ORDER BY '#comments' DESC LIMIT 100
### Instruction: list all flights on CO leaving DENVER on sunday after 2134 ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service, city, date_day, days, flight WHERE ((date_day.day_number = 27 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.departure_time > 2134 AND flight.flight_days = days.days_code) AND city.city_code = airport_service.city_code AND city.city_name = 'DENVER' AND flight.from_airport = airport_service.airport_code) AND flight.airline_code = 'CO'
### Instruction: In the morning , what times are there for the FRENCH 490 course ? ### Response:
SELECT DISTINCT course_offering.end_time, course_offering.start_time, semester.semester, semester.year 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 = 'FRENCH' AND course.number = 490 AND semester.semester = 'semester0' AND semester.semester_id = course_offering.semester AND semester.year = year0
### Instruction: what is the daily minimum amount of foley that patient 5865 had during their last hospital visit? ### Response:
SELECT MIN(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 = 5865 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'foley' AND d_items.linksto = 'outputevents') GROUP BY STRFTIME('%y-%m-%d', outputevents.charttime)
### Instruction: Interactions with a specific user (I.e., answered their question or commented on a post.). Have I interacted with this user before? (I.e., answered their question or commented on a post.) ### Response:
SELECT 'Answer' AS Type, q.Id AS "post_link", NULL AS "comment_link", a.CreationDate AS Date, a.OwnerUserId AS "useridf" FROM Posts AS a, Posts AS q WHERE a.ParentId = q.Id AND a.PostTypeId = 2 UNION ALL SELECT 'Comment' AS Type, c.PostId AS "post_link", c.Id AS "comment_link", c.CreationDate AS Date, c.UserId AS UserIDC FROM Comments AS c, Posts AS p WHERE c.PostId = p.Id ORDER BY Date
### Instruction: asked and closed per week. ### Response:
WITH closedPerWeek AS (SELECT weeksAgo, COUNT(*) AS closedQuestions FROM (SELECT DATEDIFF(week, ClosedDate, GETDATE()) AS weeksAgo FROM Posts AS p WHERE PostTypeId = 1 AND NOT ClosedDate IS NULL) AS a GROUP BY weeksAgo), askedPerWeek AS (SELECT weeksAgo, COUNT(*) AS askedQuestions FROM (SELECT DATEDIFF(week, CreationDate, GETDATE()) AS weeksAgo FROM Posts AS p WHERE PostTypeId = 1) AS a GROUP BY weeksAgo) SELECT c.weeksAgo, c.closedQuestions, a.askedQuestions FROM closedPerWeek AS c JOIN askedPerWeek AS a ON c.weeksAgo = a.weeksAgo ORDER BY weeksAgo
### Instruction: how many days have passed since the last time that patient 033-22108 was prescribed morphine sulfate during their current hospital encounter? ### Response:
SELECT 1 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', 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 = '033-22108') AND patient.hospitaldischargetime IS NULL) AND medication.drugname = 'morphine sulfate' ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: for the patients with 30s , what is the top three most frequent diagnosis for the patients? ### Response:
SELECT d_icd_diagnoses.short_title FROM d_icd_diagnoses WHERE d_icd_diagnoses.icd9_code IN (SELECT t1.icd9_code FROM (SELECT diagnoses_icd.icd9_code, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM diagnoses_icd WHERE diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.age BETWEEN 30 AND 39) GROUP BY diagnoses_icd.icd9_code) AS t1 WHERE t1.c1 <= 3)
### Instruction: tell me the minimum hospital cost that involves a percu endosc gastrostomy procedure during a year before? ### Response:
SELECT MIN(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.hadm_id IN (SELECT procedures_icd.hadm_id FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'percu endosc gastrostomy')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY cost.hadm_id) AS t1
### Instruction: First Time Posts that are on bounty questions. ### Response:
SELECT COUNT(DISTINCT p.Id) AS QuestionWithBounty, COUNT(DISTINCT Answer.Id) AS BountyAnswers, SUM(CASE WHEN PostsBeforeBounty.Id IS NULL THEN 1 ELSE 0 END) AS FirstTimePosts FROM Posts AS P INNER JOIN Votes AS bStart ON p.Id = bStart.PostId AND bStart.VoteTypeId = 8 INNER JOIN Posts AS Answer ON Answer.ParentId = p.Id AND Answer.CreationDate > bStart.CreationDate LEFT JOIN Posts AS PostsBeforeBounty ON Answer.OwnerUserId = PostsBeforeBounty.OwnerUserId AND Answer.CreationDate > PostsBeforeBounty.CreationDate
### Instruction: what flights leave PHOENIX on AA ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE (CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PHOENIX' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND flight.airline_code = 'AA'
### Instruction: Number of questions asked by a group of users in 30 days. ### Response:
WITH Questions AS (SELECT Id, OwnerUserId, Score, CreationDate FROM Posts WHERE OwnerUserId IN (SELECT VALUE FROM STRING_SPLIT('##UserIDs:string##', ','))) SELECT q.Id AS "post_link", q.OwnerUserId AS "user_link", q.Score, q.CreationDate, COUNT(*) AS "# of Qs in 30 days" FROM Questions AS q INNER JOIN Questions AS q2 ON DATEDIFF(DAY, q2.CreationDate, CreationDate) BETWEEN 0 AND 30 GROUP BY q.Id, q.OwnerUserId, q.Score, q.CreationDate ORDER BY q.CreationDate DESC
### Instruction: how much is the minimum total hospital cost that includes prsnl hst oth nfct parst since 2105? ### Response:
SELECT MIN(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.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 = 'prsnl hst oth nfct parst')) AND STRFTIME('%y', cost.chargetime) >= '2105' GROUP BY cost.hadm_id) AS t1
### Instruction: Which professor is running the ULCS classes next Winter ? ### Response:
SELECT DISTINCT instructor.name 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_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 program_course.category LIKE '%ULCS%' AND semester.semester = 'Winter' AND semester.year = 2017
### Instruction: count the number of times that patient 32154 since 11/19/2101 had a urine out foley output. ### Response:
SELECT COUNT(*) 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 = 32154)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'urine out foley' AND d_items.linksto = 'outputevents') AND STRFTIME('%y-%m-%d', outputevents.charttime) >= '2101-11-19'
### Instruction: Who teaches the easiest MDE course ? ### Response:
SELECT DISTINCT instructor.name, program_course.workload 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 program_course ON program_course.course_id = course_offering.course_id WHERE program_course.category LIKE '%MDE%' AND program_course.workload = (SELECT MIN(PROGRAM_COURSEalias1.workload) FROM program_course AS PROGRAM_COURSEalias1 WHERE PROGRAM_COURSEalias1.category LIKE '%MDE%')
### Instruction: when was patient 15945 last having the maximum value of glucose in 12/this year? ### Response:
SELECT labevents.charttime FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 15945) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'glucose') AND DATETIME(labevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', labevents.charttime) = '12' ORDER BY labevents.valuenum DESC, labevents.charttime DESC LIMIT 1
### Instruction: tell me the total amount of pigtail infusion that patient 7165 has taken on the first intensive care unit visit? ### Response:
SELECT SUM(inputevents_cv.amount) FROM inputevents_cv WHERE inputevents_cv.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 7165) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime LIMIT 1) AND inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'pigtail infusion' AND d_items.linksto = 'inputevents_cv')
### Instruction: what was the total tpn/ppn intake amount amount that patient 015-23047 had received since 578 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 = '015-23047')) AND intakeoutput.celllabel = 'tpn/ppn intake amount' AND intakeoutput.cellpath LIKE '%intake%' AND DATETIME(intakeoutput.intakeoutputtime) >= DATETIME(CURRENT_TIME(), '-578 day')
### Instruction: What is the name of the professor teaching Other class next Winter ? ### Response:
SELECT DISTINCT instructor.name 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_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 program_course.category LIKE '%Other%' AND semester.semester = 'Winter' AND semester.year = 2017
### Instruction: calculate how many times patient 017-16041 had taken vascular 3 flush amount (ml) since 04/15/2103. ### Response:
SELECT COUNT(*) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '017-16041')) AND intakeoutput.cellpath LIKE '%intake%' AND intakeoutput.celllabel = 'vascular 3 flush amount (ml)' AND STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime) >= '2103-04-15'
### Instruction: list all flights on CO leaving DENVER ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE (CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DENVER' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND flight.airline_code = 'CO'