instruction
stringlengths
53
549
output
stringlengths
30
2.33k
### Instruction: Avid answerers of the site, monthly history. ### Response:
WITH Raw AS (SELECT DATEFROMPARTS(TIME_TO_STR(CreationDate, '%Y'), TIME_TO_STR(CreationDate, '%M'), 1) AS Month, OwnerUserId AS UserId, CASE WHEN COUNT(*) > '##MaxCountPerMonth:int?5##' THEN '##MaxCountPerMonth##' ELSE COUNT(*) END AS AnswerCount FROM Posts WHERE PostTypeId = 2 AND OwnerUserId > 0 AND CreationDate < @TsNow GROUP BY DATEFROMPARTS(TIME_TO_STR(CreationDate, '%Y'), TIME_TO_STR(CreationDate, '%M'), 1), OwnerUserId) SELECT Month, AnswerCount, COUNT(*) AS UserCount FROM Raw GROUP BY Month, AnswerCount ORDER BY Month, AnswerCount
### Instruction: Find Questions Migrated Without the User. Use this query to find where users have their post migrated but they never followed the question to the target site. ### Response:
SELECT OwnerDisplayName, Posts.Id AS "post_link", PostHistory.CreationDate AS "migration_date", Posts.CreationDate AS "original_post_date", SUBSTRING(PostHistory.Comment, 13, STR_POSITION(SUBSTRING(PostHistory.Comment, 13, LENGTH(PostHistory.Comment)), '.') - 1) AS "source_site" FROM Posts JOIN PostHistory ON Posts.Id = PostHistory.PostId WHERE PostHistory.PostHistoryTypeId = 36 AND Posts.PostTypeId = 1 AND OwnerUserId IS NULL ORDER BY 5, OwnerDisplayName, Posts.CreationDate DESC
### Instruction: i want to fly from DALLAS to SAN FRANCISCO ### 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 = 'SAN FRANCISCO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: what is the name of the treatment which has been given to patient 025-27850 two or more times in the previous month? ### 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 = '025-27850')) AND DATETIME(treatment.treatmenttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') GROUP BY treatment.treatmentname) AS t1 WHERE t1.c1 >= 2
### Instruction: Users with at least 'minAnswers' answers, all scoring at least 'minScore'. ### Response:
SELECT uu.Id AS "user_link", aCt.aCt AS NumAnswers FROM Users AS uu INNER JOIN (SELECT uuu.Id, COUNT(*) AS aCt FROM Posts AS pp INNER JOIN Users AS uuu ON pp.OwnerUserId = uuu.Id WHERE pp.PostTypeId = 2 GROUP BY uuu.Id) AS aCt ON uu.Id = aCt.Id WHERE uu.Id NOT IN (SELECT u.Id FROM Posts AS p INNER JOIN Users AS u ON p.OwnerUserId = u.Id WHERE p.Score >= '##minScore##' AND p.PostTypeId = 2) AND aCt.aCt >= '##minAnswers##'
### Instruction: i would like information on flights leaving from WASHINGTON 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 = 'WASHINGTON' 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: Find the first and last name of the staff members who reported problems from the product 'rem' but not 'aut'? ### Response:
SELECT T3.staff_first_name, T3.staff_last_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T2.product_name = "rem" EXCEPT SELECT T3.staff_first_name, T3.staff_last_name FROM problems AS T1 JOIN product AS T2 JOIN staff AS T3 ON T1.product_id = T2.product_id AND T1.reported_by_staff_id = T3.staff_id WHERE T2.product_name = "aut"
### Instruction: how many days have passed since last ascorbic acid 500 mg tab was prescribed to patient 013-28507 in this hospital visit? ### 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 = '013-28507') AND patient.hospitaldischargetime IS NULL) AND medication.drugname = 'ascorbic acid 500 mg tab' ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: show flights from PHILADELPHIA 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 = 'PHILADELPHIA' 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 flights are there from MEMPHIS to LAS VEGAS ### 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 = 'MEMPHIS' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'LAS VEGAS' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Which of the courses that I 've taken is considered the hardest ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, program_course.workload FROM course INNER JOIN student_record ON student_record.course_id = course.course_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE program_course.workload = (SELECT MAX(PROGRAM_COURSEalias1.workload) FROM program_course AS PROGRAM_COURSEalias1 INNER JOIN student_record AS STUDENT_RECORDalias1 ON STUDENT_RECORDalias1.course_id = PROGRAM_COURSEalias1.course_id WHERE STUDENT_RECORDalias1.student_id = 1) AND student_record.student_id = 1
### Instruction: Posts with activity after your last comment. ### Response:
SELECT P.Id AS "post_link", P.LastActivityDate, C.Id AS "comment_link", C.CreationDate, P.OwnerUserId AS "user_link", P.LastEditorUserId AS "user_link" FROM Comments AS C INNER JOIN Posts AS P ON P.Id = C.PostId WHERE C.UserId = '##UserId:int##' AND C.CreationDate = (SELECT MAX(a.CreationDate) FROM Comments AS a WHERE a.UserId = C.UserId AND a.PostId = C.PostId) AND (C.CreationDate < P.LastActivityDate) AND (P.OwnerUserId != C.UserId) AND (P.LastEditorUserId != C.UserId) ORDER BY P.LastActivityDate DESC
### Instruction: What are the names of the tourist attractions that have parking or shopping as their feature details? ### Response:
SELECT T1.Name FROM Tourist_Attractions AS T1 JOIN Tourist_Attraction_Features AS T2 ON T1.tourist_attraction_id = T2.tourist_attraction_id JOIN Features AS T3 ON T2.Feature_ID = T3.Feature_ID WHERE T3.feature_Details = 'park' UNION SELECT T1.Name FROM Tourist_Attractions AS T1 JOIN Tourist_Attraction_Features AS T2 ON T1.tourist_attraction_id = T2.tourist_attraction_id JOIN Features AS T3 ON T2.Feature_ID = T3.Feature_ID WHERE T3.feature_Details = 'shopping'
### Instruction: BALTIMORE to PHILADELPHIA ### 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 = 'BALTIMORE' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHILADELPHIA' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: what is the percentile of 874.0 in alt (sgpt) given the same age of patient 015-21757 when they came to the hospital last time? ### Response:
SELECT DISTINCT t1.c1 FROM (SELECT lab.labresult, PERCENT_RANK() OVER (ORDER BY lab.labresult) AS c1 FROM lab WHERE lab.labname = 'alt (sgpt)' AND lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age = (SELECT patient.age FROM patient WHERE patient.uniquepid = '015-21757' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1))) AS t1 WHERE t1.labresult = 874.0
### Instruction: Questions and accepted answers are both first-posts. ### Response:
WITH Raw AS (SELECT MIN(Id) AS Id FROM Posts WHERE OwnerUserId > 0 GROUP BY OwnerUserId) SELECT Q.Id AS "post_link", * FROM Posts AS Q, Posts AS A WHERE Q.AcceptedAnswerId = A.Id AND Q.Id IN (SELECT Id FROM Raw) AND A.Id IN (SELECT Id FROM Raw) AND Q.OwnerUserId > 0 AND A.OwnerUserId > 0 AND Q.OwnerUserId != A.OwnerUserId AND Q.Score > 0 AND A.Score > 0 AND Q.CommunityOwnedDate IS NULL AND A.CommunityOwnedDate IS NULL AND NOT Q.ClosedDate IS NULL ORDER BY Q.Score + A.Score DESC, Q.Id LIMIT 100
### Instruction: i'd like a return flight from BALTIMORE 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 = 'BALTIMORE' 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: Top SO iOS users in krakow.. ### Response:
SELECT DisplayName AS "display_name", Users.Id AS "user_link", SUM(CASE Votes.VoteTypeId WHEN 2 THEN 1 WHEN 3 THEN -1 END) AS Score FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.Id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Users ON Posts.OwnerUserId = Users.Id INNER JOIN Votes ON Votes.PostId = Posts.Id WHERE (LOWER(Location) LIKE '%krak%' OR LOWER(Location) LIKE '%cracow%') AND (Tags.TagName = 'ios' OR Tags.TagName = 'objective-c' OR Tags.TagName = 'swift') AND Reputation > 10 GROUP BY DisplayName, Users.Id ORDER BY Score DESC
### Instruction: what is the minimum value of sao2 of patient 007-2001 on 01/22/last year? ### 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 = '007-2001')) AND NOT vitalperiodic.sao2 IS NULL AND DATETIME(vitalperiodic.observationtime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m-%d', vitalperiodic.observationtime) = '01-22'
### Instruction: Get all questions and answerers from 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 = 'pandas' AND p.CreationDate <= '2020'
### Instruction: what was the total amount of output for patient 002-35416 on 05/06/last year? ### 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 = '002-35416')) AND intakeoutput.cellpath LIKE '%output%' AND DATETIME(intakeoutput.intakeoutputtime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m-%d', intakeoutput.intakeoutputtime) = '05-06'
### Instruction: What are the specifics of availability for section in RCHUMS 586 from the hour of 9:00 to 4:00 ? ### 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 <= '4:00' AND course_offering.start_time >= '9:00' AND course.course_id = course_offering.course_id AND course.department = 'RCHUMS' AND course.number = 586 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: What class is easier if the choice is between EECS 555 and EECS 651 ? ### Response:
SELECT DISTINCT course.number FROM course INNER JOIN program_course ON program_course.course_id = course.course_id WHERE (course.number = 555 OR course.number = 651) 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 = 555 OR COURSEalias1.number = 651) AND COURSEalias1.department = 'EECS')
### Instruction: history of stroke ( s ) with lasting impairment to vision or the visual system, coagulopathy, uncontrolled hypertension ( i.e., systolic bp > 170 or diastolic bp > 100 ) and uncontrolled or insulin requiring diabetes. ### Response:
SELECT * FROM table_train_145 WHERE stroke = 1 AND (visual_impairment = 1 OR visual_impairment = 1 OR coagulopathy = 1 OR hypertension = 1 OR (systolic_blood_pressure_sbp > 170 OR diastolic_blood_pressure_dbp > 100)) OR (uncontrolled = 1 OR insulin_requiring_diabetes = 1)
### Instruction: awt', 'swing', 'javafx', 'wpf', 'qt', 'swt', 'jsf', 'gwt', 'vaadin', 'wicket'. ### Response:
SELECT DATEADD(month, DATEDIFF(month, 0, CreationDate), 0) AS m, TagName, COUNT(*) FROM PostTags AS pt JOIN Posts AS q ON q.Id = pt.PostId JOIN Tags AS t ON t.Id = pt.TagId WHERE TagName IN ('awt', 'swing', 'javafx', 'wpf', 'qt', 'swt', 'jsf', 'gwt', 'vaadin', 'wicket') GROUP BY DATEADD(month, DATEDIFF(month, 0, CreationDate), 0), TagName ORDER BY DATEADD(month, DATEDIFF(month, 0, CreationDate), 0)
### Instruction: i need a ticket from NASHVILLE to 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 = 'NASHVILLE' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SEATTLE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Ben Craig took EARTH 586 , taught by which professor ? ### Response:
SELECT DISTINCT instructor.name FROM instructor INNER JOIN offering_instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN student_record ON student_record.offering_id = offering_instructor.offering_id INNER JOIN student ON student.student_id = student_record.student_id INNER JOIN course_offering ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN course ON course.course_id = course_offering.course_id WHERE course.department = 'EARTH' AND course.number = 586 AND student.firstname LIKE 'Ben' AND student.lastname LIKE 'Craig'
### Instruction: how many times in 05/last year did patient 1903 produce a tf residual 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 = 1903)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'tf residual' AND d_items.linksto = 'outputevents') AND DATETIME(outputevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', outputevents.charttime) = '05'
### Instruction: what is the daily maximum dose of iv other given to patient 028-43966 since 93 months ago? ### Response:
SELECT MAX(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 = '028-43966')) AND intakeoutput.celllabel = 'iv other' AND intakeoutput.cellpath LIKE '%intake%' AND DATETIME(intakeoutput.intakeoutputtime) >= DATETIME(CURRENT_TIME(), '-93 month') GROUP BY STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime)
### Instruction: when is the first time that patient 14671 has the maximum arterial bp mean value on the current icu visit? ### 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 = 14671) AND icustays.outtime IS NULL) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'arterial bp mean' AND d_items.linksto = 'chartevents') ORDER BY chartevents.valuenum DESC, chartevents.charttime LIMIT 1
### Instruction: when was the last time in this year patient 2489 had received a periph nerve transposit? ### 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 = 'periph nerve transposit') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 2489) AND DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') ORDER BY procedures_icd.charttime DESC LIMIT 1
### Instruction: how many hours has it been since patient 030-42006's first hepatic encephalopathy diagnosis in the current 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 = 'hepatic encephalopathy' ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: Orphan questions that were migrated from another site and may be self-answered. Questions that were migrated and have no owner, and that have an answer from a registered user with the same name. ### Response:
SELECT q.Id AS "post_link", q.CreationDate AS "date", q.OwnerDisplayName AS "user_name", a.OwnerUserId AS "user_link", ph.Comment AS "comment" FROM Posts AS q INNER JOIN PostHistory AS ph ON ph.PostId = q.Id INNER JOIN Posts AS a ON a.ParentId = q.Id AND a.OwnerDisplayName = q.OwnerDisplayName WHERE ph.PostHistoryTypeId = 17 AND q.PostTypeId = 1 AND q.OwnerUserId IS NULL AND NOT a.OwnerUserId IS NULL ORDER BY q.Id DESC LIMIT 1000
### Instruction: what is patient 004-32341's last sao2 on this month/09? ### Response:
SELECT 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 = '004-32341')) AND NOT vitalperiodic.sao2 IS NULL AND DATETIME(vitalperiodic.observationtime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') AND STRFTIME('%d', vitalperiodic.observationtime) = '09' ORDER BY vitalperiodic.observationtime DESC LIMIT 1
### Instruction: Have I taken any courses that are among the most difficult in the NERS department ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, program_course.workload FROM course INNER JOIN student_record ON student_record.course_id = course.course_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE course.department = 'NERS' AND program_course.workload = (SELECT MAX(PROGRAM_COURSEalias1.workload) FROM program_course AS PROGRAM_COURSEalias1 INNER JOIN course AS COURSEalias1 ON PROGRAM_COURSEalias1.course_id = COURSEalias1.course_id WHERE COURSEalias1.department = 'NERS') AND student_record.student_id = 1
### Instruction: show flights from ATLANTA to BALTIMORE ### 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 = 'ATLANTA' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BALTIMORE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Which tags are coming with which tags most likely together?. ### Response:
SELECT MIN(SrcTags.TagName) AS "tagname", MIN(DstTags.TagName) AS HasAlso, 1.0 * COUNT(*) / MIN(SrcTags.Count) AS P FROM PostTags AS SrcPostTags, PostTags AS DstPostTags, Tags AS SrcTags, Tags AS DstTags WHERE SrcPostTags.PostId = DstPostTags.PostId AND SrcPostTags.TagId != DstPostTags.TagId AND SrcTags.Id = SrcPostTags.TagId AND DstTags.Id = DstPostTags.TagId GROUP BY SrcPostTags.TagId, DstPostTags.TagId HAVING COUNT(*) < MIN(SrcTags.Count) ORDER BY P DESC LIMIT 100
### Instruction: show me the flights from BALTIMORE 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 = 'BALTIMORE' 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: how much did patient 594 weigh last measured since 05/2103? ### 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 = 594)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'admit wt' AND d_items.linksto = 'chartevents') AND STRFTIME('%y-%m', chartevents.charttime) >= '2103-05' ORDER BY chartevents.charttime DESC LIMIT 1
### Instruction: Answers from users whose first answer is in 2015. ### Response:
SELECT q.Id AS "post_link", a.Id AS "answer_link", a.Score AS "votes", u.CreationDate AS "user_arrival", q.Tags AS "tags" FROM Posts AS a JOIN Users AS u ON a.OwnerUserId = u.Id JOIN Posts AS q ON q.Id = a.ParentId WHERE u.CreationDate >= STR_TO_TIME('1 JAN 2015', '%d %b %Y') AND u.CreationDate < STR_TO_TIME('1 JAN 2016', '%d %b %Y') AND a.Score >= @votes AND (@tag = '' OR q.Tags LIKE '%<' + @tag + '>%') ORDER BY u.CreationDate
### Instruction: what was the daily maximum amount of wound vac #2 given to patient 48637 on the first icu visit? ### Response:
SELECT MAX(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 = 48637) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime LIMIT 1) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'wound vac #2' AND d_items.linksto = 'outputevents') GROUP BY STRFTIME('%y-%m-%d', outputevents.charttime)
### Instruction: what was patient 25312 first height until 07/2105? ### 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 = 25312)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'admit ht' AND d_items.linksto = 'chartevents') AND STRFTIME('%y-%m', chartevents.charttime) <= '2105-07' ORDER BY chartevents.charttime LIMIT 1
### Instruction: show me the flights from NEWARK to LOS ANGELES ### 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 = 'LOS ANGELES' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: URLs of Argentinian users ordered by reputation. This is a query to quickly find resources (blogs, web sites) of people in a certain location (if the user entered it on the site). ### Response:
SELECT Id, DisplayName, Reputation, Location, CreationDate, LastAccessDate, AboutMe, UpVotes, WebsiteUrl FROM Users WHERE (Location LIKE '%India%' OR Location LIKE '%Mumbai%' OR Location LIKE '%Delhi%' OR Location LIKE '%Bangalore%' OR Location LIKE '%Hyderabad%' OR Location LIKE '%Manila%' OR Location LIKE '%Bangladesh%' OR Location LIKE '%Philippines%' OR Location LIKE '%Pakistan%' OR Location LIKE '%Toronto%' OR Location LIKE '%Kerala%' OR Location LIKE '%Cebu%' OR Location LIKE '%Davao%') AND WebsiteUrl != ' ' ORDER BY Reputation DESC
### Instruction: had patient 018-115975 undergone any treatment of hyperkalemia - insulin / glucose procedure in another hospital in 2105? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.uniquepid = '018-115975' AND patient.hospitalid <> (SELECT DISTINCT patient.hospitalid FROM patient WHERE patient.uniquepid = '018-115975' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'treatment of hyperkalemia - insulin / glucose' AND STRFTIME('%y', treatment.treatmenttime) = '2105'
### Instruction: show me all flights from DENVER to BURBANK ### 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 = 'BURBANK' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: when did patient 006-157753 since 10/09/2101 had evd output for the last time? ### 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 = '006-157753')) AND intakeoutput.cellpath LIKE '%output%' AND intakeoutput.celllabel = 'evd' AND STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime) >= '2101-10-09' ORDER BY intakeoutput.intakeoutputtime DESC LIMIT 1
### Instruction: tell me the name of the organism found on the last sputum, expectorated microbiology test of patient 031-15417 until 20 months ago? ### 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 = 'sputum, expectorated' AND DATETIME(microlab.culturetakentime) <= DATETIME(CURRENT_TIME(), '-20 month') ORDER BY microlab.culturetakentime DESC LIMIT 1
### Instruction: when patient 002-20631 was prescribed furosemide (lasix) tab 40 mg first time a month before. ### Response:
SELECT medication.drugstarttime FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '002-20631')) AND medication.drugname = 'furosemide (lasix) tab 40 mg' AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY medication.drugstarttime LIMIT 1
### Instruction: show me all flights from MIAMI to NEW YORK ### 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 = 'MIAMI' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'NEW YORK' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Which Average population (x 1000) has a Crude death rate (per 1000) smaller than 10.9, and a Crude birth rate (per 1000) smaller than 19.7, and a Natural change (per 1000) of 8.7, and Live births of 54 263? ### Response:
SELECT "Average population (x 1000)" FROM table_78656 WHERE "Crude death rate (per 1000)" < '10.9' AND "Crude birth rate (per 1000)" < '19.7' AND "Natural change (per 1000)" = '8.7' AND "Live births" = '54 263'
### Instruction: calculate the number of patients that had received a remve ext hrt assist sys procedure two or more times in 2105. ### 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 = 'remve ext hrt assist sys') AND STRFTIME('%y', procedures_icd.charttime) = '2105' GROUP BY admissions.subject_id) AS t1 WHERE t1.c1 >= 2
### Instruction: how much did patient 3677 weigh last measured until 26 months ago? ### 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 = 3677)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'admit wt' AND d_items.linksto = 'chartevents') AND DATETIME(chartevents.charttime) <= DATETIME(CURRENT_TIME(), '-26 month') ORDER BY chartevents.charttime DESC LIMIT 1
### Instruction: what was the last output on 12/31/this year for patient 55360? ### 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 = 55360)) AND DATETIME(outputevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m-%d', outputevents.charttime) = '12-31' ORDER BY outputevents.charttime DESC LIMIT 1)
### Instruction: Between EECS 588 and EECS 569 , which would be easier ? ### Response:
SELECT DISTINCT course.number FROM course INNER JOIN program_course ON program_course.course_id = course.course_id WHERE (course.number = 588 OR course.number = 569) 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 = 588 OR COURSEalias1.number = 569) AND COURSEalias1.department = 'EECS')
### Instruction: when was patient 15447 first measured a arterial bp [diastolic] on the current intensive care unit visit? ### 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 = 15447) AND icustays.outtime IS NULL) 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.charttime LIMIT 1
### Instruction: when was the first time until 1182 days ago that patient 010-6010's sao2 was measured greater than 96.0? ### 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-6010')) AND vitalperiodic.sao2 > 96.0 AND NOT vitalperiodic.sao2 IS NULL AND DATETIME(vitalperiodic.observationtime) <= DATETIME(CURRENT_TIME(), '-1182 day') ORDER BY vitalperiodic.observationtime LIMIT 1
### Instruction: show me flights from NEW YORK to MIAMI ### 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 = 'NEW YORK' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'MIAMI' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: in 12/2105 has patient 006-158338's systemicdiastolic been normal? ### Response:
SELECT COUNT(*) > 0 FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-158338')) AND vitalperiodic.systemicdiastolic BETWEEN diastolic_bp_lower AND diastolic_bp_upper AND NOT vitalperiodic.systemicdiastolic IS NULL AND STRFTIME('%y-%m', vitalperiodic.observationtime) = '2105-12'
### Instruction: when's the first time patient 022-44805 had the maximum chloride in 12/this year? ### 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 = '022-44805')) AND lab.labname = 'chloride' AND DATETIME(lab.labresulttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', lab.labresulttime) = '12' ORDER BY lab.labresult DESC, lab.labresulttime LIMIT 1
### Instruction: please list all flights between BOSTON and 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 = 'BOSTON' 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: In the past what classes has Dr. Jasmine Zheng 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 '%Jasmine Zheng%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: show me the flights from DALLAS 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 = 'DALLAS' 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: what percentile of the calcium value is a 8.9 among a patient of the same age as patient 022-78464 when they came to the hospital last time? ### Response:
SELECT DISTINCT t1.c1 FROM (SELECT lab.labresult, PERCENT_RANK() OVER (ORDER BY lab.labresult) AS c1 FROM lab WHERE lab.labname = 'calcium' AND lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age = (SELECT patient.age FROM patient WHERE patient.uniquepid = '022-78464' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1))) AS t1 WHERE t1.labresult = 8.9
### Instruction: when was the first time the temperature c (calc) measured in patient 7524 on the first icu visit? ### 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 = 7524) 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 = 'temperature c (calc)' AND d_items.linksto = 'chartevents') ORDER BY chartevents.charttime LIMIT 1
### Instruction: Find users from a user's questions. ### Response:
WITH CTE AS (SELECT OwnerUserId, Id, ParentId, PostTypeId FROM Posts WHERE OwnerUserId = '##UserID##' AND PostTypeId = 1 UNION ALL SELECT p.OwnerUserId, p.Id, p.ParentId, p.PostTypeId FROM CTE AS e INNER JOIN Posts AS p ON p.ParentId = e.Id AND p.PostTypeId = 2) SELECT c.OwnerUserId AS "user_link", u.DisplayName, u.Reputation, c.Id, q.Title, c.ParentId FROM CTE AS c LEFT OUTER JOIN Users AS u ON u.Id = c.OwnerUserId LEFT OUTER JOIN Posts AS q ON q.Id = c.ParentId WHERE c.PostTypeId = 2
### Instruction: what was the name of the procedure performed to patient 030-52327, two times during this month? ### 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 = '030-52327')) AND DATETIME(treatment.treatmenttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') GROUP BY treatment.treatmentname) AS t1 WHERE t1.c1 = 2
### Instruction: Stack Overflow questions with outstanding close votes (PHP Tag). A list of Stack Overflow questions with outstanding close votes, sorted by number of votes. ### Response:
SELECT * FROM (SELECT Posts.Id AS "post_link", AVG(Posts.Score) AS "score", COUNT(*) AS "close_votes", MAX(Votes.CreationDate) AS "last_vote", MIN(Votes.CreationDate) AS "first_vote" FROM Posts INNER JOIN Votes ON Posts.Id = Votes.PostId WHERE Votes.VoteTypeId = 6 AND Posts.ClosedDate IS NULL AND Posts.Tags LIKE '%<php>%' GROUP BY Posts.Id) AS Myview WHERE 'close_votes' > 3 ORDER BY 'last_vote' DESC, 'score', 'close_votes' DESC
### Instruction: what was the name of the drug that was prescribed two times to patient 013-28507 since 10/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 = '013-28507')) AND STRFTIME('%y-%m', medication.drugstarttime) >= '2104-10' GROUP BY medication.drugname) AS t1 WHERE t1.c1 = 2
### Instruction: what was the average daily number of patients who were admitted for hernia, site nec w obstr until 3 years ago? ### 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 = 'hernia, site nec w obstr') AND DATETIME(diagnoses_icd.charttime) <= DATETIME(CURRENT_TIME(), '-3 year') GROUP BY STRFTIME('%y-%m-%d', diagnoses_icd.charttime)) AS t1
### Instruction: Questions with a specific tag and no other tags. ### Response:
SELECT Id AS "post_link", Tags FROM Posts WHERE PostTypeId = 1 AND NOT Tags LIKE '<star-trek>' AND (Tags LIKE '<star-trek-%>' OR Tags LIKE '<the-wrath-of-khan>' OR Tags LIKE '<the-search-for-spock>' OR Tags LIKE '<the-voyage-home>' OR Tags LIKE '<the-final-frontier>' OR Tags LIKE '<the-undiscovered-country>' OR Tags LIKE '<uss-enterprise>' OR Tags LIKE '<federation>' OR Tags LIKE '<vulcan>' OR Tags LIKE '<klingon>' OR Tags LIKE '<romulan>' OR Tags LIKE '<borg>' OR Tags LIKE '<changeling>' OR Tags LIKE '<klingon-language>') ORDER BY Tags, Title
### Instruction: from LAS VEGAS to PHOENIX ### 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 = 'LAS VEGAS' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHOENIX' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: Score per answer for users with at least 10 answers in the past 30 days in a tag.. ### Response:
SELECT Posts.OwnerUserId AS "user_link", SUM(Score) AS Score, COUNT(*) AS Answers, ROUND(1.0 * SUM(Score) / COUNT(*), 2) AS ScorePerAnswer FROM Posts WHERE Posts.ParentId IN (SELECT Posts.Id FROM Posts INNER JOIN PostTags ON PostTags.PostId = Posts.Id INNER JOIN Tags ON Tags.Id = PostTags.TagId WHERE Tags.TagName = @TagName) AND Posts.CreationDate >= DATEADD(DAY, -30, GETDATE()) AND Posts.CreationDate <= GETDATE() GROUP BY Posts.OwnerUserId HAVING COUNT(*) > 10 ORDER BY ScorePerAnswer DESC
### Instruction: how many hours have elapsed since the first time on their current hospital visit patient 012-31752 was diagnosed with nutritional deficiency? ### 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 = '012-31752' AND patient.hospitaldischargetime IS NULL)) AND diagnosis.diagnosisname = 'nutritional deficiency' ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: what was the organism found in patient 8324's first microbiology test of the sputum in 07/last year? ### Response:
SELECT microbiologyevents.org_name FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 8324) 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) = '07' ORDER BY microbiologyevents.charttime LIMIT 1
### Instruction: flights from ONTARIO to ORLANDO ### 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 = 'ONTARIO' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ORLANDO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: flight from BOSTON to BALTIMORE ### 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 = 'BALTIMORE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: in this year, did patient 033-4763 get a anticonvulsants - valproate operation in other hospitals? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.uniquepid = '033-4763' AND patient.hospitalid <> (SELECT DISTINCT patient.hospitalid FROM patient WHERE patient.uniquepid = '033-4763' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'anticonvulsants - valproate' AND DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')
### Instruction: calculate the amount of 7.7meq naacetate patient 7524 has taken on the last icu visit. ### Response:
SELECT SUM(inputevents_cv.amount) FROM inputevents_cv WHERE inputevents_cv.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 7524) 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 = '7.7meq naacetate' AND d_items.linksto = 'inputevents_cv')
### Instruction: first time patient 9833 was diagnosed with dermatitis nos in this year? ### 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 = 'dermatitis nos') AND diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 9833) AND DATETIME(diagnoses_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') ORDER BY diagnoses_icd.charttime LIMIT 1
### Instruction: when was the last time that patient 6170 got a urine out foley output today? ### 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 = 6170)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'urine out foley' AND d_items.linksto = 'outputevents') AND DATETIME(outputevents.charttime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-0 day') ORDER BY outputevents.charttime DESC LIMIT 1
### Instruction: what was patient 28966 last height until 3 months ago? ### 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 = 28966)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'admit ht' AND d_items.linksto = 'chartevents') AND DATETIME(chartevents.charttime) <= DATETIME(CURRENT_TIME(), '-3 month') ORDER BY chartevents.charttime DESC LIMIT 1
### Instruction: what flights are there from NEWARK to TAMPA ### 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 = 'TAMPA' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: has .45% normal saline been given during the last month to patient 8562? ### Response:
SELECT COUNT(*) > 0 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 = 8562)) AND inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = '.45% normal saline' AND d_items.linksto = 'inputevents_cv') AND DATETIME(inputevents_cv.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### Instruction: what was the drug patient 016-27397 had been prescribed two times this month? ### 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 = '016-27397')) AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') GROUP BY medication.drugname) AS t1 WHERE t1.c1 = 2
### 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: 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: 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: 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: 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: 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