instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: Between EECS 545 and EECS 587 what is easier ? ### Response:
SELECT DISTINCT course.number FROM course INNER JOIN program_course ON program_course.course_id = course.course_id WHERE (course.number = 545 OR course.number = 587) AND program_course.workload = (SELECT MIN(PROGRAM_COURSEalias1.workload) FROM program_course AS PROGRAM_COURSEalias1 INNER JOIN course AS COURSEalias1 ON PROGRAM_COURSEalias1.course_id = COURSEalias1.course_id WHERE (COURSEalias1.number = 545 OR COURSEalias1.number = 587) AND COURSEalias1.department = 'EECS')
### Instruction: ARTDES 210 is taught by how many professors during Spring-Summer 2017 ? ### 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 = 'ARTDES' AND course.number = 210 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 = 2017
### Instruction: show flights from DALLAS to OAKLAND ### 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 = 'DALLAS' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'OAKLAND' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Answers score by blazor tag. ### Response:
WITH C AS (SELECT p.Id 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 CreationDate > '2017-09-23' AND t.TagName = 'blazor' AND (PostTypeId = 1)) SELECT COUNT(*), CASE WHEN Score < 0 THEN '<0' WHEN Score = 0 THEN '=0' WHEN Score > 0 THEN '>0' END AS score2 FROM Posts AS p INNER JOIN c ON p.ParentId = c.Id GROUP BY CASE WHEN Score < 0 THEN '<0' WHEN Score = 0 THEN '=0' WHEN Score > 0 THEN '>0' END ORDER BY score2
### Instruction: pericardial disease or heart transplant. patients with left bundle branch block, pulmonary hypertension, known systolic dysfunction ( ejection fraction < 40 % ) , receiving vasopressors, known moderate or severe valvular dysfunction, and irregular heart rhythms will be enrolled but analyzed separately ### Response:
SELECT * FROM table_train_55 WHERE pericardial_disease = 1 OR heart_transplant = 1 OR (left_bundle_branch_block = 1 OR pulmonary_hypertension = 1 OR (systolic_dysfunction = 1 OR ejection_fraction_ef < 40) OR receiving_vasopressor = 1 OR valvular_dysfunction = 1 OR heart_disease = 1)
### Instruction: what is the name of a drug patient 009-9534 had been prescribed two or more times until 08/2104? ### 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 = '009-9534')) AND STRFTIME('%y-%m', medication.drugstarttime) <= '2104-08' GROUP BY medication.drugname) AS t1 WHERE t1.c1 >= 2
### Instruction: uncontrolled blood pressure: systolic blood pressure > 140 mmhg or diastolic blood pressure > 80 mmhg evidence of renal dysfunction, serum creatinine > 1.5 mg / dl ( male ) and 1.4 mg / dl ( female ) ### Response:
SELECT * FROM table_dev_41 WHERE uncontrolled_blood_pressure = 1 OR (systolic_blood_pressure_sbp > 140 OR diastolic_blood_pressure_dbp > 80) OR renal_disease = 1 OR ((serum_creatinine > 1.5 AND gender = 'male') OR (serum_creatinine > 1.4 AND gender = 'female'))
### Instruction: what is patient 25814 last diagnosis time of long-term use meds nec since 2105? ### 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 = 'long-term use meds nec') AND diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25814) AND STRFTIME('%y', diagnoses_icd.charttime) >= '2105' ORDER BY diagnoses_icd.charttime DESC LIMIT 1
### Instruction: indicate the daily minimum volume of t tube that patient 027-8953 has had on the first intensive care unit visit. ### Response:
SELECT MIN(intakeoutput.cellvaluenumeric) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '027-8953') AND NOT patient.unitdischargetime IS NULL ORDER BY patient.unitadmittime LIMIT 1) AND intakeoutput.celllabel = 't tube' AND intakeoutput.cellpath LIKE '%output%' GROUP BY STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime)
### Instruction: what flights are available from BOSTON to DALLAS ### 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 = 'BOSTON' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DALLAS' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: list the AS flights from BURBANK to anywhere ### 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 = 'BURBANK' 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 = 'AS'
### Instruction: What are the classes that Dr. Patrick Seitzer has taught ? ### 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 '%Patrick Seitzer%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: Which classes did Dr. Franke Varca teach 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 '%Franke Varca%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: when did patient 004-34394 last get a prescription for acetaminophen 650 mg re supp since 05/2102? ### 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 = '004-34394')) AND medication.drugname = 'acetaminophen 650 mg re supp' AND STRFTIME('%y-%m', medication.drugstarttime) >= '2102-05' ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: what was the name of the medication which was prescribed to patient 005-76912 the last time in 07/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 = '005-76912')) AND DATETIME(medication.drugstarttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', medication.drugstarttime) = '07' ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: tell me how much patient 021-213732's total output was on last month/08. ### 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 = '021-213732')) AND intakeoutput.cellpath LIKE '%output%' AND DATETIME(intakeoutput.intakeoutputtime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') AND STRFTIME('%d', intakeoutput.intakeoutputtime) = '08'
### Instruction: calculate the total amount of chest tube output: pleural l output for patient 007-849 since 10/28/2103. ### 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 = '007-849')) AND intakeoutput.celllabel = 'chest tube output: pleural l' AND intakeoutput.cellpath LIKE '%output%' AND STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime) >= '2103-10-28'
### Instruction: show me all the flights arriving in CHARLOTTE around 5pm next monday please ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service, city, date_day, days, flight WHERE ((flight.arrival_time <= 1730 AND flight.arrival_time >= 1630) AND date_day.day_number = 21 AND date_day.month_number = 2 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code) AND city.city_code = airport_service.city_code AND city.city_name = 'CHARLOTTE' AND flight.to_airport = airport_service.airport_code
### Instruction: how many hours has it been since patient 025-50213 was last diagnosed with lower urinary tract infection during their current hospital encounter. ### 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 = '025-50213' AND patient.hospitaldischargetime IS NULL)) AND diagnosis.diagnosisname = 'lower urinary tract infection' ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: what is the minimum daily number of patients with tobacco use disorder diagnosed the last year? ### 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 = 'tobacco use disorder') AND DATETIME(diagnoses_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY STRFTIME('%y-%m-%d', diagnoses_icd.charttime)) AS t1
### Instruction: Physiology Masters Research Project will be offered at what times ? ### Response:
SELECT DISTINCT course_offering.end_time, course_offering.friday, course_offering.monday, course_offering.saturday, course_offering.start_time, course_offering.sunday, course_offering.thursday, course_offering.tuesday, course_offering.wednesday FROM semester INNER JOIN course_offering ON semester.semester_id = course_offering.semester INNER JOIN course ON course.course_id = course_offering.course_id WHERE course.name LIKE '%Physiology Masters Research Project%' AND semester.semester = 'FA' AND semester.year = 2016
### Instruction: had patient 10211 had heart rate less than 124.0 during their first hospital encounter? ### 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 = 10211 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 = 'heart rate' AND d_items.linksto = 'chartevents') AND chartevents.valuenum < 124.0
### Instruction: Count of Posts Downvoted per Month. ### Response:
SELECT Users.Id AS "user_link", CAST(TIME_TO_STR(Votes.CreationDate, '%Y.%m.%d') AS TEXT(7)) AS LeMonth, COUNT(*) AS Downvotes FROM (SELECT DISTINCT Votes.PostId, Votes.CreationDate FROM Votes WHERE Votes.VoteTypeId = 3) AS Votes INNER JOIN Posts ON Votes.PostId = Posts.Id INNER JOIN Users ON Posts.OwnerUserId = Users.Id WHERE Users.DisplayName = '##username##' GROUP BY Users.Id, CAST(TIME_TO_STR(Votes.CreationDate, '%Y.%m.%d') AS TEXT(7)) ORDER BY LeMonth, DownVotes DESC
### Instruction: Which classes has Dr. Kt Tomey taught before ? ### 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 '%Kt Tomey%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: Average number of votes on all sites. For each site, show the average number of votes per post (questions and answers alike) ### Response:
SELECT COUNT(*) * 1.0 / (SELECT COUNT(*) FROM Posts WHERE PostTypeId = 1 OR PostTypeId = 2) AS "votes", COUNT(CASE VoteTypeId WHEN 2 THEN 1 END) * 1.0 / (SELECT COUNT(*) FROM Posts WHERE PostTypeId = 1 OR PostTypeId = 2) AS "upvotes", COUNT(CASE VoteTypeId WHEN 3 THEN 1 END) * 1.0 / (SELECT COUNT(*) FROM Posts WHERE PostTypeId = 1 OR PostTypeId = 2) AS "downvotes" FROM Votes WHERE (VoteTypeId = 2 OR VoteTypeId = 3)
### Instruction: Num of Score Buckets for High Score Questions where last edit user is in >200 bucket and original us. ### Response:
SELECT COUNT(DISTINCT Score) FROM Posts AS p JOIN (SELECT DISTINCT PostId FROM PostHistory WHERE PostHistoryTypeId IN (4, 5, 6)) AS ph ON PostId = p.Id JOIN Users AS u ON p.OwnerUserId = u.Id JOIN Users AS lu ON p.LastEditorUserId = lu.Id WHERE p.PostTypeId = 1 AND u.Reputation < 200 AND p.OwnerUserId != p.LastEditorUserId AND p.DeletionDate IS NULL AND p.CommunityOwnedDate IS NULL AND p.ClosedDate IS NULL AND lu.Reputation >= 200 AND p.Score >= 10
### Instruction: what is the average total hospital cost to include intracranial/cerebral perfusion pressure monitoring - cerebral tissue oxygenation monitor since 2103? ### Response:
SELECT AVG(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT treatment.patientunitstayid FROM treatment WHERE treatment.treatmentname = 'intracranial/cerebral perfusion pressure monitoring - cerebral tissue oxygenation monitor')) AND STRFTIME('%y', cost.chargetime) >= '2103' GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: when is the first time that patient 027-136854 had the minimum value of sao2 since 10/06/2104? ### 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 = '027-136854')) AND NOT vitalperiodic.sao2 IS NULL AND STRFTIME('%y-%m-%d', vitalperiodic.observationtime) >= '2104-10-06' ORDER BY vitalperiodic.sao2, vitalperiodic.observationtime LIMIT 1
### Instruction: Which came first? Badge or post?. ### Response:
WITH first_post AS (SELECT MIN(p.Id) AS PostId, COUNT(DISTINCT p.Id) AS posts, OwnerUserId FROM Posts AS p GROUP BY OwnerUserId) SELECT COUNT(*) AS N, COALESCE(Name, 'none') AS Badge, ROUND(AVG(1.0 * posts), 2) AS avg_posts, ROUND(AVG(1.0 * Score), 2) AS avg_score FROM first_post AS fp JOIN Posts AS p ON fp.PostId = p.Id LEFT OUTER JOIN Badges AS b ON p.OwnerUserId = b.UserId AND Date < p.CreationDate GROUP BY COALESCE(Name, 'none') ORDER BY COUNT(*) DESC
### Instruction: Users with the most amount of Questions and no Accepted Solutions. ### Response:
SELECT U.DisplayName, U.Reputation, COUNT(DISTINCT Q.Id) AS Questions, COUNT(A.Id) AS AnswersReceived FROM Users AS U JOIN Posts AS Q ON U.Id = Q.OwnerUserId JOIN PostTypes AS QT ON Q.PostTypeId = QT.Id JOIN Posts AS A ON Q.Id = A.ParentId JOIN PostTypes AS AT ON A.PostTypeId = AT.Id WHERE QT.Name = 'Question' AND AT.Name = 'Answer' AND Q.DeletionDate IS NULL AND Q.AnswerCount > 0 GROUP BY U.DisplayName, U.Reputation HAVING COUNT(Q.AcceptedAnswerId) = 0 ORDER BY Questions DESC LIMIT 50
### Instruction: i would like to fly from DENVER to BOSTON ### 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 = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: when was patient 017-45919 first received mannitol - bolus .25-.5 gms/kg during this year? ### Response:
SELECT 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 = '017-45919')) AND treatment.treatmentname = 'mannitol - bolus .25-.5 gms/kg' AND DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') ORDER BY treatment.treatmenttime LIMIT 1
### Instruction: what was the drug which until 34 months ago had been prescribed to patient 004-66442 two or more times? ### 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 = '004-66442')) AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-34 month') GROUP BY medication.drugname) AS t1 WHERE t1.c1 >= 2
### Instruction: has there been any organism found in the last sputum, tracheal specimen microbiological test of patient 031-17834 in 2105? ### 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 = '031-17834')) AND microlab.culturesite = 'sputum, tracheal specimen' AND STRFTIME('%y', microlab.culturetakentime) = '2105' ORDER BY microlab.culturetakentime DESC LIMIT 1
### Instruction: In the Fall of 2017 how many professors will teach MICRBIOL 995 ? ### 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 = 'MICRBIOL' AND course.number = 995 AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'Fall' AND semester.semester_id = course_offering.semester AND semester.year = 2017
### Instruction: Prof. Jonathan Freedman has taught which courses ? ### 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 '%Jonathan Freedman%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: until 04/18/2101, list the daily average sao2 of patient 012-35195. ### Response:
SELECT AVG(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 = '012-35195')) AND NOT vitalperiodic.sao2 IS NULL AND STRFTIME('%y-%m-%d', vitalperiodic.observationtime) <= '2101-04-18' GROUP BY STRFTIME('%y-%m-%d', vitalperiodic.observationtime)
### Instruction: what was the dose of lidocaine jelly 2% (urojet) - that was last prescribed to patient 24921 in 09/last year? ### Response:
SELECT prescriptions.dose_val_rx FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 24921) AND prescriptions.drug = 'lidocaine jelly 2% (urojet)' AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', prescriptions.startdate) = '09' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: AWS Answers by Month for a given User. ### Response:
SELECT CAST(TIME_TO_STR(Answer.CreationDate, '%Y-%m-%d') AS TEXT(7)) AS Month, COUNT(Answer.Id) AS Answers FROM Posts AS Answer JOIN Posts AS Question ON Question.Id = Answer.ParentId WHERE Question.PostTypeId = 1 AND Answer.PostTypeId = 2 AND (Question.Tags LIKE '%<amazon-%' OR Question.Tags LIKE '%<aws-%') AND Answer.OwnerUserId = '##UserId##' GROUP BY CAST(TIME_TO_STR(Answer.CreationDate, '%Y-%m-%d') AS TEXT(7)) ORDER BY CAST(TIME_TO_STR(Answer.CreationDate, '%Y-%m-%d') AS TEXT(7))
### Instruction: For section in ENSCEN 541 between 9:00 and 3:00 , what is the availability ? ### Response:
SELECT DISTINCT course_offering.end_time, course_offering.section_number, course_offering.start_time FROM course, course_offering, semester WHERE course_offering.end_time <= '3:00' AND course_offering.start_time >= '9:00' AND course.course_id = course_offering.course_id AND course.department = 'ENSCEN' AND course.number = 541 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: TOP JavaScript users in Oxford. ### Response:
WITH USER_BY_TAG AS (SELECT ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC) AS Rank, u.Id AS "user_link", COUNT(*) AS UpVotes, u.age FROM Tags AS t INNER JOIN PostTags AS pt ON pt.TagId = t.Id INNER JOIN Posts AS p ON p.ParentId = pt.PostId INNER JOIN Votes AS v ON v.PostId = p.Id AND VoteTypeId = 2 INNER JOIN Users AS u ON u.Id = p.OwnerUserId WHERE LOWER(Location) LIKE '%new york%' AND TagName = 'javascript' GROUP BY u.Id, TagName, u.age) SELECT * FROM USER_BY_TAG WHERE rank <= 1000 ORDER BY UpVotes DESC
### Instruction: List of Not-Closed Community Wiki Posts. List of Not-Closed Community Wiki Posts Get all Question and Answer that are Community Wiki but not closed. Don't list all answers of a Community Wiki Question because they are all Community Wiki anyway. ### Response:
SELECT PostTypes.Name, Posts.Id AS "post_link", Posts.Score AS Score, Posts.CreationDate FROM Posts INNER JOIN PostTypes ON Posts.PostTypeId = PostTypes.Id LEFT JOIN Posts AS ParentPosts ON Posts.ParentId = ParentPosts.Id WHERE Posts.PostTypeId IN (1, 2) AND NOT (Posts.CommunityOwnedDate IS NULL) AND (ParentPosts.CommunityOwnedDate IS NULL) ORDER BY Posts.CreationDate
### Instruction: flights from PHOENIX to NEWARK ### 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 = 'NEWARK' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Up vs Down votes by hour of day. Doesn't currently work, but that's just because the data isn't currently there. ### Response:
SELECT TIME_TO_STR(p.CreationDate, '%-HOUR') AS Hour, (CAST(SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS FLOAT) / CAST(SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS FLOAT)) AS UpVoteDownVoteRatio FROM Votes AS v JOIN Posts AS p ON p.Id = PostId WHERE p.Score >= 0 GROUP BY TIME_TO_STR(p.CreationDate, '%-HOUR') ORDER BY TIME_TO_STR(p.CreationDate, '%-HOUR')
### Instruction: what is a drug that patient 030-30152 was prescribed two or more times since 143 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 = '030-30152')) AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-143 month') GROUP BY medication.drugname) AS t1 WHERE t1.c1 >= 2
### Instruction: when has patient 035-24054 last had a enteral nepro intake yesterday? ### Response:
SELECT intakeoutput.intakeoutputtime FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '035-24054')) AND intakeoutput.cellpath LIKE '%intake%' AND intakeoutput.celllabel = 'enteral nepro' AND DATETIME(intakeoutput.intakeoutputtime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-1 day') ORDER BY intakeoutput.intakeoutputtime DESC LIMIT 1
### Instruction: what is the name of the procedure that has been done two times in 12/2105 to patient 004-64091? ### 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 = '004-64091')) AND STRFTIME('%y-%m', treatment.treatmenttime) = '2105-12' GROUP BY treatment.treatmentname) AS t1 WHERE t1.c1 = 2
### Instruction: what organism has been found in the last blood, venipuncture exam of patient 031-15417 until 08/2104? ### Response:
SELECT microlab.organism FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-15417')) AND microlab.culturesite = 'blood, venipuncture' AND STRFTIME('%y-%m', microlab.culturetakentime) <= '2104-08' ORDER BY microlab.culturetakentime DESC LIMIT 1
### Instruction: what was the name of the output which patient 10855 had for the first time on this month/25? ### 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 = 10855)) AND DATETIME(outputevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') AND STRFTIME('%d', outputevents.charttime) = '25' ORDER BY outputevents.charttime LIMIT 1)
### Instruction: how much did patient 24894 weigh first measured when they visited the hospital last 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 = 24894 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC 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: what was the last value of the systemicdiastolic for patient 006-119203 until 03/17/2104? ### Response:
SELECT vitalperiodic.systemicdiastolic FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-119203')) AND NOT vitalperiodic.systemicdiastolic IS NULL AND STRFTIME('%y-%m-%d', vitalperiodic.observationtime) <= '2104-03-17' ORDER BY vitalperiodic.observationtime DESC LIMIT 1
### Instruction: give me the total amount of wound vac #1 that patient 92788 produces since 06/28/2104. ### 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 = 92788)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'wound vac #1' AND d_items.linksto = 'outputevents') AND STRFTIME('%y-%m-%d', outputevents.charttime) >= '2104-06-28'
### Instruction: show me all NX flights from TORONTO ### 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 = 'TORONTO' 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 = 'NX'
### Instruction: when did patient 23061 have the first foley output until 10/25/2101. ### Response:
SELECT outputevents.charttime 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 = 23061)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'foley' AND d_items.linksto = 'outputevents') AND STRFTIME('%y-%m-%d', outputevents.charttime) <= '2101-10-25' ORDER BY outputevents.charttime LIMIT 1
### Instruction: when did patient 52898 receive a gastric tube irrigat nec procedure for the first time since 2105? ### 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 = 'gastric tube irrigat nec') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 52898) AND STRFTIME('%y', procedures_icd.charttime) >= '2105' ORDER BY procedures_icd.charttime LIMIT 1
### Instruction: what was the average value for sao2 for patient 016-18150 on last month/03? ### Response:
SELECT AVG(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 = '016-18150')) AND NOT vitalperiodic.sao2 IS NULL AND DATETIME(vitalperiodic.observationtime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') AND STRFTIME('%d', vitalperiodic.observationtime) = '03'
### Instruction: Total number of comments that contains keyword by year and month. ### Response:
SELECT CAST(YEAR(CreationDate) AS TEXT(4)) + '-' + RIGHT('00' + CAST(MONTH(CreationDate) AS TEXT(2)), 2) AS year_month, COUNT(*) AS total FROM Comments WHERE (UPPER(Text) LIKE '%DEVOPS%') GROUP BY CAST(YEAR(CreationDate) AS TEXT(4)) + '-' + RIGHT('00' + CAST(MONTH(CreationDate) AS TEXT(2)), 2) ORDER BY CAST(YEAR(CreationDate) AS TEXT(4)) + '-' + RIGHT('00' + CAST(MONTH(CreationDate) AS TEXT(2)), 2)
### Instruction: had patient 030-47098 been treated since 4 years ago in other hospitals with a administration of electrolytes - intravenous procedure? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.uniquepid = '030-47098' AND patient.hospitalid <> (SELECT DISTINCT patient.hospitalid FROM patient WHERE patient.uniquepid = '030-47098' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'administration of electrolytes - intravenous' AND DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-4 year')
### Instruction: Top Responders to Java questions in the UK or England. ### Response:
WITH posts_WITH_java_tags AS (SELECT PostId FROM PostTags AS pt LEFT JOIN Tags AS t ON pt.TagId = t.Id WHERE LOWER(t.TagName) = 'java') SELECT u.Id AS "user_link", u.Reputation, COUNT(*) AS number_of_answers FROM Posts AS p INNER JOIN posts_WITH_java_tags AS pt ON pt.PostId = p.Id INNER JOIN Posts AS a ON a.ParentId = p.Id LEFT JOIN Users AS u ON a.OwnerUserId = U.Id WHERE (LOWER(Location) LIKE '%uk%' OR LOWER(Location) LIKE '%england%') GROUP BY u.Id, u.Reputation ORDER BY number_of_answers DESC
### Instruction: what was the name of the drug prescribed in 12/2105 to patient 018-20179 two times? ### 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 = '018-20179')) AND STRFTIME('%y-%m', medication.drugstarttime) = '2105-12' GROUP BY medication.drugname) AS t1 WHERE t1.c1 = 2
### Instruction: how many hours has it been since the first time during their current hospital visit that patient 016-38131 was diagnosed with pain - moderate? ### 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 = '016-38131' AND patient.hospitaldischargetime IS NULL)) AND diagnosis.diagnosisname = 'pain - moderate' ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: Between 10:00 and 5:00 , is there a section of JUDAIC 381 ? ### Response:
SELECT DISTINCT course_offering.end_time, course_offering.section_number, course_offering.start_time FROM course, course_offering, semester WHERE course_offering.end_time <= '5:00' AND course_offering.start_time >= '10:00' AND course.course_id = course_offering.course_id AND course.department = 'JUDAIC' AND course.number = 381 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: had patient 62298 been diagnosed as hpt b chrn wo cm wo dlta in this year? ### Response:
SELECT COUNT(*) > 0 FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'hpt b chrn wo cm wo dlta') AND diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 62298) AND DATETIME(diagnoses_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')
### Instruction: Tags grouped by open questions. ### Response:
SELECT 'open_questions', COUNT(*) AS tagcount FROM (SELECT COUNT(*) - COUNT(Posts.ClosedDate) AS "open_questions" FROM Posts JOIN PostTags ON (Posts.Id = PostTags.PostId) JOIN Tags ON (PostTags.TagId = Tags.Id) LEFT JOIN TagSynonyms AS a ON (Tags.TagName = a.SourceTagName) LEFT JOIN TagSynonyms AS b ON (a.TargetTagName = b.SourceTagName) LEFT JOIN TagSynonyms AS c ON (b.TargetTagName = c.SourceTagName) WHERE Posts.PostTypeId = 1 GROUP BY COALESCE(c.TargetTagName, b.TargetTagName, a.TargetTagName, Tags.TagName)) AS t GROUP BY 'open_questions' ORDER BY 'open_questions'
### Instruction: when was the first time the respiration for patient 015-58787 was less than 29.0 today? ### 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 = '015-58787')) AND vitalperiodic.respiration < 29.0 AND NOT vitalperiodic.respiration IS NULL AND DATETIME(vitalperiodic.observationtime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-0 day') ORDER BY vitalperiodic.observationtime LIMIT 1
### Instruction: Tags where users ask their first question. ### Response:
SELECT Tags.TagName, COUNT(DISTINCT Posts.Id) AS first_questions, Tags.Count AS total_questions, COUNT(DISTINCT Posts.Id) * 1.0 / Tags.Count AS ratio_of_questions_that_are_first_questions FROM Posts INNER JOIN (SELECT OwnerUserId, MIN(CreationDate) AS first_post FROM Posts GROUP BY OwnerUserId) AS sq ON Posts.OwnerUserId = sq.OwnerUserId AND Posts.CreationDate = sq.first_post INNER JOIN PostTags ON PostTags.PostId = Posts.Id INNER JOIN Tags ON PostTags.TagId = Tags.Id WHERE Posts.PostTypeId = 1 GROUP BY Tags.TagName, Tags.Count ORDER BY 4 DESC
### Instruction: how many hours has it been since patient 030-42006 first carbon monoxide overdose diagnosis on 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 = '030-42006' AND patient.hospitaldischargetime IS NULL)) AND diagnosis.diagnosisname = 'carbon monoxide overdose' ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: when was the first time that during this year patient 005-77687 was diagnosed with acute copd exacerbation. ### 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 = '005-77687')) AND diagnosis.diagnosisname = 'acute copd exacerbation' AND DATETIME(diagnosis.diagnosistime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: Questions entered in the review queue (in the date range). ### Response:
SELECT PostId AS "post_link", url = 'site://review/' + CASE '##type?2##' WHEN 1 THEN 'suggested-edits' WHEN 2 THEN 'close' WHEN 3 THEN 'low-quality-posts' WHEN 4 THEN 'first-posts' WHEN 5 THEN 'late-answers' WHEN 6 THEN 'reopen' END + '/' + CAST(Id AS TEXT), CreationDate FROM ReviewTasks WHERE (ReviewTaskTypeId = '##type##') AND (CreationDate >= '##Date1?2020-01-01##') AND (CreationDate <= '##Date2?2020-03-01##') ORDER BY Id DESC LIMIT 100
### Instruction: count the number of times patient 83038 has had chest tubes cticu ct 1 since 11/2101. ### 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 = 83038)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'chest tubes cticu ct 1' AND d_items.linksto = 'outputevents') AND STRFTIME('%y-%m', outputevents.charttime) >= '2101-11'
### Instruction: on the last icu visit when did patient 25433 get tpn for the last time? ### 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 = 25433) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime DESC LIMIT 1) AND inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'tpn' AND d_items.linksto = 'inputevents_cv') ORDER BY inputevents_cv.charttime DESC LIMIT 1
### Instruction: what is the name of the organism found in patient 031-16123's first microbiological nasopharynx test since 09/2104? ### Response:
SELECT microlab.organism FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-16123')) AND microlab.culturesite = 'nasopharynx' AND STRFTIME('%y-%m', microlab.culturetakentime) >= '2104-09' ORDER BY microlab.culturetakentime LIMIT 1
### Instruction: show all flights on LH out of BOSTON ### 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 = 'BOSTON' 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 = 'LH'
### Instruction: when did patient 010-16572 last have a maximum value of systemicsystolic during yesterday? ### 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 = '010-16572')) AND NOT vitalperiodic.systemicsystolic IS NULL AND DATETIME(vitalperiodic.observationtime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-1 day') ORDER BY vitalperiodic.systemicsystolic DESC, vitalperiodic.observationtime DESC LIMIT 1
### Instruction: count the number of times patient 23858 has been given a tpn d15.0 until 75 months ago. ### 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 = 23858)) AND inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'tpn d15.0' AND d_items.linksto = 'inputevents_cv') AND DATETIME(inputevents_cv.charttime) <= DATETIME(CURRENT_TIME(), '-75 month')
### Instruction: what was the last time that patient 70516 had a maximum value of anion gap in 11/last year? ### Response:
SELECT labevents.charttime FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 70516) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'anion gap') AND DATETIME(labevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', labevents.charttime) = '11' ORDER BY labevents.valuenum DESC, labevents.charttime DESC LIMIT 1
### Instruction: what is the average daily number of people diagnosed with cv dis nec-deliver w p/p until 2102? ### Response:
SELECT AVG(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 = 'cv dis nec-deliver w p/p') AND STRFTIME('%y', diagnoses_icd.charttime) <= '2102' GROUP BY STRFTIME('%y-%m-%d', diagnoses_icd.charttime)) AS t1
### Instruction: was there an organism found in the last microbiological test of patient 031-9128's sputum, tracheal specimen until 2104? ### 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 = '031-9128')) AND microlab.culturesite = 'sputum, tracheal specimen' AND STRFTIME('%y', microlab.culturetakentime) <= '2104' ORDER BY microlab.culturetakentime DESC LIMIT 1
### Instruction: when was patient 009-11964 last tested in 07/last year for alkaline phos.? ### 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 = '009-11964')) AND lab.labname = 'alkaline phos.' AND DATETIME(lab.labresulttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', lab.labresulttime) = '07' ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: PreMajor classes next Winter are being taught by who ? ### 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 '%PreMajor%' AND semester.semester = 'Winter' AND semester.year = 2017
### Instruction: until 7 months ago, when patient 005-4044 was prescribed for the first time for magnesium sulfate 2gm/50ml? ### 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 = '005-4044')) AND medication.drugname = 'magnesium sulfate 2gm/50ml' AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-7 month') ORDER BY medication.drugstarttime LIMIT 1
### Instruction: Vanity: Which users earned a particular tag-based badge sooner than me?. ### Response:
SELECT Users.DisplayName, Users.Id, DATEDIFF(day, Users.CreationDate, Date) AS Days FROM Badges INNER JOIN Users ON Users.Id = Badges.UserId WHERE Badges.Class = @BadgeType AND Badges.TagBased = 1 AND Badges.Name = @BadgeName AND DATEDIFF(day, Users.CreationDate, Date) <= (SELECT DATEDIFF(day, Users.CreationDate, Date) FROM Badges INNER JOIN Users ON Users.Id = Badges.UserId WHERE Badges.Class = @BadgeType AND Badges.TagBased = 1 AND Badges.Name = @BadgeName AND Badges.UserId = @UserId) ORDER BY Days
### Instruction: show flights between BOSTON and 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 = 'BOSTON' 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: there were any organism found in patient 93078's first sputum microbiology test in 06/last year? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 93078) AND microbiologyevents.spec_type_desc = 'sputum' AND NOT microbiologyevents.org_name IS NULL AND DATETIME(microbiologyevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', microbiologyevents.charttime) = '06' ORDER BY microbiologyevents.charttime LIMIT 1
### Instruction: Of all the MATSCIE 400 classes which ones are in the morning . ### 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 = 'MATSCIE' AND course.number = 400 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: what percentile is the mch of 29.0 among patients of the same age as patient 006-254232 during the first 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 = 'mch' AND lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age = (SELECT patient.age FROM patient WHERE patient.uniquepid = '006-254232' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1))) AS t1 WHERE t1.labresult = 29.0
### Instruction: At what times in the morning is the course WOMENSTD 698 ? ### 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 = 'WOMENSTD' AND course.number = 698 AND semester.semester = 'semester0' AND semester.semester_id = course_offering.semester AND semester.year = year0
### Instruction: since 1271 days ago when was the last bulb #1 output time for patient 005-77687? ### Response:
SELECT intakeoutput.intakeoutputtime FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '005-77687')) AND intakeoutput.cellpath LIKE '%output%' AND intakeoutput.celllabel = 'bulb #1' AND DATETIME(intakeoutput.intakeoutputtime) >= DATETIME(CURRENT_TIME(), '-1271 day') ORDER BY intakeoutput.intakeoutputtime DESC LIMIT 1
### Instruction: when did patient 61339 last receive a ven cath renal dialysis, until 3 years ago? ### 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 = 'ven cath renal dialysis') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 61339) AND DATETIME(procedures_icd.charttime) <= DATETIME(CURRENT_TIME(), '-3 year') ORDER BY procedures_icd.charttime DESC LIMIT 1
### Instruction: ELT Informatica Oracle in Moscow - Mathematics. ### Response:
WITH USER_BY_TAG AS (SELECT ROW_NUMBER() OVER (ORDER BY Reputation DESC) AS "#", u.Id AS "user_link", u.Reputation FROM Tags AS t INNER JOIN PostTags AS pt ON pt.TagId = t.Id INNER JOIN Posts AS p ON p.ParentId = pt.PostId INNER JOIN Votes AS v ON v.PostId = p.Id AND VoteTypeId = 2 INNER JOIN Users AS u ON u.Id = p.OwnerUserId WHERE LOWER(Location) LIKE '%moscow%' AND (TagName = 'elt' OR TagName = 'informatica') GROUP BY u.Id, TagName, u.Reputation) SELECT * FROM USER_BY_TAG ORDER BY Reputation DESC
### Instruction: indicate the daily average amount of arterial bp [systolic] for patient 9474. ### Response:
SELECT AVG(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 = 9474)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'arterial bp [systolic]' AND d_items.linksto = 'chartevents') GROUP BY STRFTIME('%y-%m-%d', chartevents.charttime)
### Instruction: Top 500 users by tag. ### Response:
SELECT ROW_NUMBER() OVER (ORDER BY Score DESC) AS "#", u.Id AS "user_link", u.DisplayName, tuser.Answers, tuser.Score, u.Reputation FROM Users AS u JOIN (SELECT Answers.OwnerUserId AS UserId, SUM(Answers.Score) AS Score, COUNT(*) AS Answers FROM Tags AS t JOIN PostTags AS pt ON t.Id = pt.TagId JOIN Posts AS p ON p.Id = pt.PostId JOIN Posts AS Answers ON Answers.ParentId = p.Id WHERE t.TagName = '##TagName##' GROUP BY Answers.OwnerUserId) AS tuser ON tuser.UserId = u.Id ORDER BY Score DESC LIMIT 500
### Instruction: During the 2007 Spring-Summer , how many professors teach PIBS 501 ? ### 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 = 'PIBS' AND course.number = 501 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 = 2007
### Instruction: show me DALLAS to BOSTON flights ### 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 = 'DALLAS' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: what is the maximum hospital cost for a person with neuropathy in diabetes during the previous year? ### Response:
SELECT MAX(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 = 'neuropathy in diabetes')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY cost.hadm_id) AS t1
### Instruction: what was the number of times that patient 006-86236 had cl flush: coated catheter subclavian l intake since 171 months ago? ### 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 = '006-86236')) AND intakeoutput.cellpath LIKE '%intake%' AND intakeoutput.celllabel = 'cl flush: coated catheter subclavian l' AND DATETIME(intakeoutput.intakeoutputtime) >= DATETIME(CURRENT_TIME(), '-171 month')
### Instruction: Posts with [ibm] that don't have any product-specific tags. ### Response:
SELECT p.Id AS "post_link", p.CreationDate AS "creation_date", p.Tags FROM Posts AS p LEFT JOIN PostTags AS pt ON p.Id = pt.PostId LEFT JOIN Tags AS t ON pt.TagId = t.Id WHERE t.TagName = 'ibm' AND NOT EXISTS(SELECT t2.Id FROM PostTags AS pt2 LEFT JOIN Tags AS t2 ON pt2.TagId = t2.Id WHERE p.Id = pt2.PostId AND t2.TagName IN ('clearcase', 'dxl', 'ibm-bpm', 'ibm-midrange', 'rad', 'rational', 'rational-rose', 'websphere', 'websphere-mq', 'worklight'))
### Instruction: tell me the average total hospital cost for a patient with chronic cholecystitis during a year before? ### Response:
SELECT AVG(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 = 'chronic cholecystitis')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY cost.hadm_id) AS t1
### Instruction: NEWARK to CLEVELAND ### 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 = 'NEWARK' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'CLEVELAND' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Always end your questions with a ?. ### Response:
SELECT TIME_TO_STR(CreationDate, '%YEAR') AS year, (CASE WHEN Title LIKE '%?' THEN 'ends WITH ?' ELSE 'does not' END) AS ends_WITH_question, ROUND(COUNT(AcceptedAnswerId) * 100 / COUNT(*), 2) AS answered, AVG(AnswerCount * 1.0) AS avg_answers FROM Posts WHERE PostTypeId = 1 GROUP BY TIME_TO_STR(CreationDate, '%YEAR'), (CASE WHEN Title LIKE '%?' THEN 'ends WITH ?' ELSE 'does not' END) ORDER BY TIME_TO_STR(CreationDate, '%YEAR'), (CASE WHEN Title LIKE '%?' THEN 'ends WITH ?' ELSE 'does not' END)