instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: the heartrate of patient 015-91239 last measured on the current icu visit is greater than it was second to last measured on the current icu visit? ### Response:
SELECT (SELECT vitalperiodic.heartrate FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '015-91239') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1) > (SELECT vitalperiodic.heartrate FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '015-91239') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1 OFFSET 1)
### Instruction: Score at time of post. ### Response:
SELECT SUM(Score) + 1 FROM (SELECT COUNT(*) * p.PostTypeId * 5 AS score FROM Posts AS p INNER JOIN Votes AS v ON v.PostId = p.Id INNER JOIN Posts AS p2 ON p2.OwnerUserId = p.OwnerUserId WHERE p2.Id = '##postid?8092417##' AND v.VoteTypeId = 2 AND p.CreationDate < p2.CreationDate AND v.CreationDate < p2.CreationDate AND p.PostTypeId IN (1, 2) GROUP BY p.PostTypeId UNION ALL SELECT COUNT(*) * -2 FROM Posts AS p INNER JOIN Votes AS v ON v.PostId = p.Id INNER JOIN Posts AS p2 ON p2.OwnerUserId = p.OwnerUserId WHERE p2.Id = '##postid?8092417##' AND v.VoteTypeId = 3 AND p.CreationDate < p2.CreationDate AND v.CreationDate < p2.CreationDate AND p.PostTypeId IN (1, 2) GROUP BY p.PostTypeId) AS t
### Instruction: what are the flights from CLEVELAND to INDIANAPOLIS for wednesday the 12 of 4 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'INDIANAPOLIS' AND date_day.day_number = 12 AND date_day.month_number = 4 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'CLEVELAND' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: How many times 'does not work was used'. ### Response:
SELECT COUNT('posts'.id) FROM Posts INNER JOIN Users ON ('posts'."owneruserid" = 'users'.id) WHERE LOWER('users'."location") LIKE '%india%' AND (LOWER('body') LIKE '%do not work%' OR LOWER('body') LIKE '%does not work%' OR LOWER('body') LIKE '%do not works%' OR LOWER('body') LIKE '%does not works%' OR LOWER('body') LIKE '%don''t work%' OR LOWER('body') LIKE '%doesn''t work%' OR LOWER('body') LIKE '%don''t works%' OR LOWER('body') LIKE '%doesn''t works%' OR LOWER('title') LIKE '%do not work%' OR LOWER('title') LIKE '%does not work%' OR LOWER('title') LIKE '%do not works%' OR LOWER('title') LIKE '%does not works%' OR LOWER('title') LIKE '%don''t work%' OR LOWER('title') LIKE '%doesn''t work%' OR LOWER('title') LIKE '%don''t works%' OR LOWER('title') LIKE '%doesn''t works%')
### Instruction: Number of Tasks per month. ### Response:
WITH a AS (SELECT Id, ReviewTaskTypeId, DATEPART(YYYY, CreationDate) + 1.00 * FLOOR((DATEPART(MM, CreationDate) - 1.00) / 3) / 4 AS "month", CASE WHEN DATEDIFF(dd, CreationDate, DeletionDate) = 0 THEN 'same day' WHEN DATEDIFF(dd, CreationDate, DeletionDate) = 1 THEN 'next day' WHEN DATEDIFF(dd, CreationDate, DeletionDate) > 1 THEN 'longer' END AS "duration" FROM ReviewTasks WHERE DATEPART(YYYY, CreationDate) + 1.00 * FLOOR((DATEPART(MM, CreationDate) - 1.00) / 3) / 4 < DATEPART(YYYY, GETDATE()) + 1.00 * FLOOR((DATEPART(MM, GETDATE()) - 1.00) / 3) / 4 AND ReviewTaskTypeId IN (2, 6)) SELECT 'month', 'duration', COUNT(Id) FROM a GROUP BY 'month', 'duration' ORDER BY 'month'
### Instruction: how many patients died after being diagnosed in 2104 with hematuria in the same hospital encounter? ### Response:
SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT t1.uniquepid, t1.diagnosistime, t1.patienthealthsystemstayid FROM (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'hematuria') AS t1 GROUP BY t1.uniquepid HAVING MIN(t1.diagnosistime) = t1.diagnosistime AND STRFTIME('%y', t1.diagnosistime) = '2104') AS t2 JOIN (SELECT patient.uniquepid, patient.patienthealthsystemstayid, patient.hospitaldischargetime FROM patient WHERE patient.hospitaldischargestatus = 'expired') AS t3 ON t2.uniquepid = t3.uniquepid WHERE t2.patienthealthsystemstayid = t3.patienthealthsystemstayid
### Instruction: what aircraft is used on DL flight 1222 from KANSAS CITY to SALT LAKE CITY ### Response:
SELECT DISTINCT aircraft.aircraft_code FROM aircraft, airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, equipment_sequence, flight WHERE ((CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'KANSAS CITY' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SALT LAKE CITY' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND flight.flight_number = 1222) AND equipment_sequence.aircraft_code = aircraft.aircraft_code AND flight.aircraft_code_sequence = equipment_sequence.aircraft_code_sequence AND flight.airline_code = 'DL'
### Instruction: what are the flights from INDIANAPOLIS to SAN DIEGO on wednesday the 12 of 4 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN DIEGO' AND date_day.day_number = 12 AND date_day.month_number = 4 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'INDIANAPOLIS' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: i would like a nonstop flight from MEMPHIS to LAS VEGAS on 3 2 ### 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, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'LAS VEGAS' AND date_day.day_number = 2 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'MEMPHIS' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.stops = 0
### Instruction: what flights go from CHICAGO to SEATTLE on CO on saturday ### 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, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SEATTLE' AND date_day.day_number = 26 AND date_day.month_number = 7 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'CHICAGO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'CO'
### Instruction: compared to last measured on the last hospital visit patient 75170's potassium is greater than the value second to last measured on the last hospital visit? ### Response:
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 75170 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'potassium') ORDER BY labevents.charttime DESC LIMIT 1) > (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 75170 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'potassium') ORDER BY labevents.charttime DESC LIMIT 1 OFFSET 1)
### Instruction: please list all flights from SAN FRANCISCO to PITTSBURGH on sunday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PITTSBURGH' AND date_day.day_number = 27 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SAN FRANCISCO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: since 5 years ago, how many patients were prescribed with aspart insulin in the same hospital visit after having received valve replacement or repair? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'valve replacement or repair' AND DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-5 year')) AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'aspart insulin' AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-5 year')) AS t2 WHERE t1.treatmenttime < t2.drugstarttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
### Instruction: until 3 years ago how many patients were diagnosed with septic shock during the same month after the previous diagnosis of chronic kidney disease? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'septic shock' AND DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-3 year')) AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'chronic kidney disease' AND DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-3 year')) AS t2 WHERE t1.diagnosistime < t2.diagnosistime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.diagnosistime, 'start of month')
### Instruction: Simple data on reputation parity above a given lower bound. ### Response:
SELECT COUNT(*) AS "total", SUM(CASE WHEN Reputation % 2 = 0 THEN 1 ELSE 0 END) AS "even", SUM(CASE WHEN Reputation % 2 = 1 THEN 1 ELSE 0 END) AS "odd", ROUND((SUM(CASE WHEN Reputation % 2 = 0 THEN 1 ELSE 0 END) * 100.0) / COUNT(*), 3) AS "%even", ROUND((SUM(CASE WHEN Reputation % 2 = 1 THEN 1 ELSE 0 END) * 100.0) / COUNT(*), 3) AS "%odd", CASE WHEN SUM(CASE WHEN Reputation % 2 = 1 THEN 1 ELSE 0 END) = 0 THEN 0 ELSE ROUND((SUM(CASE WHEN Reputation % 2 = 0 THEN 1 ELSE 0 END) * 1.0) / SUM(CASE WHEN Reputation % 2 = 1 THEN 1 ELSE 0 END), 3) END AS "even/odd", ROUND(AVG(Reputation * 1.0), 3) AS "mean" FROM Users WHERE Reputation >= '##lowerBound##'
### Instruction: count the number of patients that died during the same month after having been diagnosed with bronchitis until 1 year ago. ### Response:
SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'bronchitis') AS t1 GROUP BY t1.uniquepid HAVING MIN(t1.diagnosistime) = t1.diagnosistime AND DATETIME(t1.diagnosistime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 JOIN (SELECT patient.uniquepid, patient.patienthealthsystemstayid, patient.hospitaldischargetime FROM patient WHERE patient.hospitaldischargestatus = 'expired') AS t3 ON t2.uniquepid = t3.uniquepid WHERE DATETIME(t2.diagnosistime, 'start of month') = DATETIME(t3.hospitaldischargetime, 'start of month')
### Instruction: is there a THURSDAY night flight from PITTSBURGH to SAN FRANCISCO on US ### 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, days, flight WHERE (((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND days.day_name = 'THURSDAY' AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'US') AND NOT flight.departure_time BETWEEN 601 AND 1759
### Instruction: Question Body length percentile and statistics with tag input. ### Response:
WITH cte AS (SELECT p.Id, NTILE(100) OVER (ORDER BY LENGTH(p.Body)) AS percentile 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 p.PostTypeId = 1 AND t.TagName = '##tagname:string##') SELECT cte.percentile, MIN(LENGTH(p.Body)) AS LengthStart, MAX(LENGTH(p.Body)) AS LengthStop, AVG(CAST(p.Score AS FLOAT(10, 4))) AS avgScore, AVG(CAST(p.AnswerCount AS FLOAT(10, 4))) AS AvgAnswerCount, AVG(CAST(p.ViewCount AS FLOAT(10, 4))) AS AvgViewCount, AVG(CAST(p.CommentCount AS FLOAT(10, 4))) AS AvgCommentCount FROM Posts AS p INNER JOIN cte ON p.Id = cte.Id GROUP BY cte.percentile ORDER BY cte.percentile
### Instruction: how many patients have undergone wound care until 1 year ago in the same month after the first procedure of a antiarrhythmics - class iv antiarrhythmic? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'antiarrhythmics - class iv antiarrhythmic' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'wound care' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month')
### Instruction: Amount of questions closed after 3 leading close votes in the Close Vote review queue. Amount of posts closed (and not closed) after 'n' leading close votes in the Close Vote review queue (counts/consider the vote/flag which triggered the review activity) AND with at least 5 close/do not close votes in total (this is to minimize the effect of binding votes cast by moderators or by tag gold badge holders). The default setup in query measures 3 leading close votes, but it can be tweaked for counting 2 and 4 leading close votes as well. Just comment and/or uncomment the INNER JOIN clauses in the 'qualified_posts' CTE (see comments' instructions there). ### Response:
SELECT p.Id AS "post_link", pf.PostId, vt.Name, pf.CreationDate FROM Posts AS p INNER JOIN PostFeedback AS pf ON pf.PostId = p.Id INNER JOIN VoteTypes AS vt ON vt.Id = pf.VoteTypeId WHERE NOT p.ClosedDate IS NULL AND pf.PostId = 3923221 ORDER BY pf.PostId, pf.CreationDate DESC LIMIT 50
### Instruction: count the number of patients who have received a bronchodilator - beta-agonist procedure within the same month after they have had a bronchodilator - ipratropium procedure until 2104. ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'bronchodilator - ipratropium' AND STRFTIME('%y', treatment.treatmenttime) <= '2104') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'bronchodilator - beta-agonist' AND STRFTIME('%y', treatment.treatmenttime) <= '2104') AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month')
### Instruction: economy fares NEW YORK to MIAMI round trip ### Response:
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, fare_basis, flight, flight_fare 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 fare_basis.economy = 'YES' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND NOT fare.round_trip_cost IS NULL
### Instruction: what number of patients were prescribed furosemide within 2 months after having been diagnosed with acute renal failure in 2101? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'acute renal failure' AND STRFTIME('%y', diagnosis.diagnosistime) = '2101') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'furosemide' AND STRFTIME('%y', medication.drugstarttime) = '2101') AS t2 WHERE t1.diagnosistime < t2.drugstarttime AND DATETIME(t2.drugstarttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month')
### Instruction: display all flights from PITTSBURGH to SAN FRANCISCO on 8 2 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND date_day.day_number = 2 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: i would like a COACH class seat on a flight leaving DENVER arriving 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, fare, fare_basis, flight, flight_fare WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ATLANTA' AND fare_basis.class_type = 'COACH' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DENVER' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: what is the two year survival rate of congestive heart failure - left-sided patients diagnosed? ### Response:
SELECT SUM(CASE WHEN patient.hospitaldischargestatus = 'alive' THEN 1 WHEN STRFTIME('%j', patient.hospitaldischargetime) - STRFTIME('%j', t2.diagnosistime) > 2 * 365 THEN 1 ELSE 0 END) * 100 / COUNT(*) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'congestive heart failure - left-sided' GROUP BY patient.uniquepid HAVING MIN(diagnosis.diagnosistime) = diagnosis.diagnosistime) AS t1 WHERE STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', t1.diagnosistime) > 2 * 365) AS t2 JOIN patient ON t2.uniquepid = patient.uniquepid
### Instruction: show the flights from PITTSBURGH to SAN FRANCISCO again on monday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' 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 flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: count the number of patients that died during the same month after having been diagnosed with dic syndrome until 2 years ago. ### Response:
SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'dic syndrome') AS t1 GROUP BY t1.uniquepid HAVING MIN(t1.diagnosistime) = t1.diagnosistime AND DATETIME(t1.diagnosistime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 JOIN (SELECT patient.uniquepid, patient.patienthealthsystemstayid, patient.hospitaldischargetime FROM patient WHERE patient.hospitaldischargestatus = 'expired') AS t3 ON t2.uniquepid = t3.uniquepid WHERE DATETIME(t2.diagnosistime, 'start of month') = DATETIME(t3.hospitaldischargetime, 'start of month')
### Instruction: count the number of patients who received a endotracheal tube procedure within the same month after being diagnosed with a encephalopathy - metabolic since 2103. ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'encephalopathy - metabolic' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2103') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'endotracheal tube' AND STRFTIME('%y', treatment.treatmenttime) >= '2103') AS t2 WHERE t1.diagnosistime < t2.treatmenttime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month')
### Instruction: compared to last measured on the last hospital visit, was the value of the hematocrit from patient 13686 less than the value first measured on the last hospital visit? ### Response:
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 13686 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'hematocrit') ORDER BY labevents.charttime DESC LIMIT 1) < (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 13686 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'hematocrit') ORDER BY labevents.charttime LIMIT 1)
### Instruction: provide a list of the five most frequent procedures that patients took during the same hospital visit following their administration of electrolytes - phosphate treatment. ### Response:
SELECT t3.treatmentname FROM (SELECT t2.treatmentname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'administration of electrolytes - phosphate') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.treatmenttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 5
### Instruction: how many patients until 2104 were diagnosed with gi bleeding within 2 months after they underwent glucose - d10w? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'glucose - d10w' AND STRFTIME('%y', treatment.treatmenttime) <= '2104') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'gi bleeding' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2104') AS t2 WHERE t1.treatmenttime < t2.diagnosistime AND DATETIME(t2.diagnosistime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month')
### Instruction: Posts (Questions) based on a given tag and a given duration. ### Response:
SELECT TIME_TO_STR(p.LastActivityDate, '%Y') AS YEAR, TIME_TO_STR(p.LastActivityDate, '%B') AS MONTH_NAME, MONTH(p.LastActivityDate) AS MONTH_NUM, COUNT(*) AS "QUESTIONS ASKED" FROM Posts AS p, PostTags AS ptags, Tags AS t, PostTypes AS ptypes WHERE p.PostTypeId = ptypes.Id AND ptypes.Id = 1 AND p.Id = ptags.PostId AND ptags.TagId = t.Id AND t.TagName = '##TagName##' AND p.CreationDate >= '##startdate##' AND p.CreationDate <= '##enddate##' GROUP BY TIME_TO_STR(p.LastActivityDate, '%Y'), MONTH(p.LastActivityDate), TIME_TO_STR(p.LastActivityDate, '%B') ORDER BY TIME_TO_STR(p.LastActivityDate, '%Y'), MONTH(p.LastActivityDate), TIME_TO_STR(p.LastActivityDate, '%B')
### Instruction: show me the flights from DALLAS to BALTIMORE in FIRST class ### 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, fare, fare_basis, flight, flight_fare WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BALTIMORE' AND fare_basis.class_type = 'FIRST' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DALLAS' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: okay and then from PITTSBURGH i'd like to travel to ATLANTA on 9 4 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ATLANTA' AND date_day.day_number = 4 AND date_day.month_number = 9 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: what is the top three most frequently prescribed drugs that were prescribed to patients within the same hospital visit after being diagnosed with pneumonia? ### Response:
SELECT t3.drugname FROM (SELECT t2.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'pneumonia') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.drugstarttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 3
### Instruction: how many patients died in the same month after being diagnosed in 2105 with nutritional deficiency? ### Response:
SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'nutritional deficiency') AS t1 GROUP BY t1.uniquepid HAVING MIN(t1.diagnosistime) = t1.diagnosistime AND STRFTIME('%y', t1.diagnosistime) = '2105') AS t2 JOIN (SELECT patient.uniquepid, patient.patienthealthsystemstayid, patient.hospitaldischargetime FROM patient WHERE patient.hospitaldischargestatus = 'expired') AS t3 ON t2.uniquepid = t3.uniquepid WHERE DATETIME(t2.diagnosistime, 'start of month') = DATETIME(t3.hospitaldischargetime, 'start of month')
### Instruction: how much is COACH flight from PITTSBURGH to ATLANTA ### Response:
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, fare_basis, flight, flight_fare WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ATLANTA' AND fare_basis.class_type = 'COACH' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: all flights from WASHINGTON to SAN FRANCISCO on 11 12 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND date_day.day_number = 12 AND date_day.month_number = 11 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'WASHINGTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: how many patients were prescribed with 5% dextrose in the same month following the diagnosis of hx of past noncompliance,? ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, diagnoses_icd.charttime FROM diagnoses_icd JOIN admissions ON diagnoses_icd.hadm_id = admissions.hadm_id WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'hx of past noncompliance')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = '5% dextrose') AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND DATETIME(t1.charttime, 'start of month') = DATETIME(t2.startdate, 'start of month')
### Instruction: what are connecting flights from CHICAGO to SEATTLE on 6 1 ### 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, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SEATTLE' AND date_day.day_number = 1 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'CHICAGO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.connections > 0
### Instruction: how many patients during the same hospital visit until 2 years ago have received insulin after the previous intravenous diuretic procedure? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'intravenous diuretic' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'insulin' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
### Instruction: show me one more time the FIRST class fares from BALTIMORE to DALLAS ### Response:
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, fare_basis, flight, flight_fare 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 fare_basis.class_type = 'FIRST' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: i'm requesting flight information on a flight from DENVER to SAN FRANCISCO on wednesday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND date_day.day_number = 23 AND date_day.month_number = 4 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DENVER' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: how many patients were prescribed with cefazolin in the same hospital visit after the analgesics - narcotic analgesic procedure since 2104? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'analgesics - narcotic analgesic' AND STRFTIME('%y', treatment.treatmenttime) >= '2104') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'cefazolin' AND STRFTIME('%y', medication.drugstarttime) >= '2104') AS t2 WHERE t1.treatmenttime < t2.drugstarttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
### Instruction: please list any flights from OAKLAND california to PHILADELPHIA on tuesday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHILADELPHIA' AND date_day.day_number = 22 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'OAKLAND' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: on tuesday i'd like to fly from DETROIT to ST. PETERSBURG ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ST. PETERSBURG' AND date_day.day_number = 22 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DETROIT' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: how many people died after being diagnosed with atelectasis/collapse within the same month in 2105? ### Response:
SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'atelectasis/collapse') AS t1 GROUP BY t1.uniquepid HAVING MIN(t1.diagnosistime) = t1.diagnosistime AND STRFTIME('%y', t1.diagnosistime) = '2105') AS t2 JOIN (SELECT patient.uniquepid, patient.patienthealthsystemstayid, patient.hospitaldischargetime FROM patient WHERE patient.hospitaldischargestatus = 'expired') AS t3 ON t2.uniquepid = t3.uniquepid WHERE DATETIME(t2.diagnosistime, 'start of month') = DATETIME(t3.hospitaldischargetime, 'start of month')
### Instruction: i'm traveling from BOSTON to ATLANTA and i'd like to go sometime after 1700 but i want to know what kind of airplane it 's on ### Response:
SELECT DISTINCT aircraft.aircraft_code FROM aircraft, airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, equipment_sequence, 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 = 'BOSTON' AND equipment_sequence.aircraft_code = aircraft.aircraft_code AND flight.aircraft_code_sequence = equipment_sequence.aircraft_code_sequence AND flight.departure_time > 1700 AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
### Instruction: show me flights which leave from BOSTON on 7 22 arriving in PITTSBURGH ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PITTSBURGH' AND date_day.day_number = 22 AND date_day.month_number = 7 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: is the heartrate value of patient 030-44598 second measured on the current icu visit less than first measured on the current icu visit? ### Response:
SELECT (SELECT vitalperiodic.heartrate FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '030-44598') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1 OFFSET 1) < (SELECT vitalperiodic.heartrate FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '030-44598') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1)
### Instruction: Script to identify Unsual vote activity. ### Response:
SELECT vdt.User_ID AS "user_link", u.Reputation AS "user_reputation", vdt.Upvote_Count AS "upvote_count", vdt.Upvoting_Occured AS "date_of_votes", vdt.Post_Count AS "number_of_posts" FROM (SELECT u.Id AS User_Id, COUNT(v.Id) AS Upvote_Count, MAX(v.CreationDate) AS Upvoting_Occured, COUNT(DISTINCT p.Id) AS Post_Count FROM Votes AS v INNER JOIN Posts AS p ON v.PostId = p.Id INNER JOIN Users AS u ON p.OwnerUserId = u.Id WHERE v.VoteTypeId = 2 GROUP BY u.Id, v.CreationDate) AS vdt INNER JOIN Users AS u ON vdt.User_Id = u.Id WHERE (vdt.Upvote_Count >= 20) AND (u.Reputation < 2000) AND (vdt.Post_Count >= 10) AND (u.Reputation != 1) ORDER BY vdt.Upvoting_Occured DESC
### Instruction: can you show me flights that are economy class 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, fare, fare_basis, flight, flight_fare WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DALLAS' AND fare_basis.economy = 'YES' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BALTIMORE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: what are the top three most common drugs prescribed to patients within 2 months after antihypertensives - labetalol? ### Response:
SELECT t3.drugname FROM (SELECT t2.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'antihypertensives - labetalol') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.drugstarttime AND DATETIME(t2.drugstarttime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month') GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 3
### Instruction: show me a list of flights from SAN FRANCISCO to BOSTON for 8 30 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BOSTON' AND date_day.day_number = 30 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SAN FRANCISCO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: show me all flights from PITTSBURGH to BALTIMORE on thursday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BALTIMORE' AND date_day.day_number = 24 AND date_day.month_number = 5 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: list the FIRST class flights from BALTIMORE 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, fare, fare_basis, flight, flight_fare WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DENVER' AND fare_basis.class_type = 'FIRST' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BALTIMORE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: round trip fares from PITTSBURGH to PHILADELPHIA under 1000 dollars ### Response:
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare WHERE (CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHILADELPHIA' AND fare.round_trip_cost < 1000 AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND NOT fare.round_trip_cost IS NULL
### Instruction: Tag Wikis with the Most Edits. ### Response:
SELECT P.Id, SUBSTRING(P.Body, 0, 80), (SELECT COUNT(V.Id) FROM Votes AS V WHERE V.PostId = P.Id AND V.VoteTypeId = 16) AS "edits", CAST(TIME_TO_STR(P.CommunityOwnedDate, '%b %d, %Y') AS TEXT(12)), CAST(TIME_TO_STR(P.LastActivityDate, '%b %d, %Y') AS TEXT(12)) FROM Posts AS P, PostTypes AS Pt, Votes AS V, VoteTypes AS Vt WHERE Pt.Id = 5 AND Vt.Id = 16 AND P.Id = V.PostId AND Vt.Id = V.VoteTypeId AND Pt.Id = P.PostTypeId AND (SELECT COUNT(V.Id) FROM Votes AS V WHERE V.PostId = P.Id AND V.VoteTypeId = 16) > 50 GROUP BY P.Id, P.Body, P.CommunityOwnedDate, P.LastActivityDate ORDER BY Edits
### Instruction: what are the flights from NASHVILLE to TACOMA on tuesday the 18 of 5 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'TACOMA' AND date_day.day_number = 18 AND date_day.month_number = 5 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'NASHVILLE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: what is the top four most frequent diagnoses that patients had during the same hospital visit after receiving neurology consultation? ### Response:
SELECT t3.diagnosisname FROM (SELECT t2.diagnosisname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'neurology consultation') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.diagnosistime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.diagnosisname) AS t3 WHERE t3.c1 <= 4
### Instruction: all right what do you have from OAKLAND to PHILADELPHIA on wednesday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHILADELPHIA' AND date_day.day_number = 23 AND date_day.month_number = 4 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'OAKLAND' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: since 2105, how many patients were prescribed with propofol within 2 months after having been diagnosed with pneumonia? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'pneumonia' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2105') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'propofol' AND STRFTIME('%y', medication.drugstarttime) >= '2105') AS t2 WHERE t1.diagnosistime < t2.drugstarttime AND DATETIME(t2.drugstarttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month')
### Instruction: the value of hematocrit second measured on the first hospital visit in patient 43959 was greater than first measured on the first hospital visit? ### Response:
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 43959 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'hematocrit') ORDER BY labevents.charttime LIMIT 1 OFFSET 1) > (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 43959 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'hematocrit') ORDER BY labevents.charttime LIMIT 1)
### Instruction: how much of patient 94956's glucose second measured on the first hospital visit changed compared to the first value measured on the first hospital visit? ### Response:
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 94956 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'glucose') ORDER BY labevents.charttime LIMIT 1 OFFSET 1) - (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 94956 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'glucose') ORDER BY labevents.charttime LIMIT 1)
### Instruction: what are the flights on tuesday 10 1 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BALTIMORE' AND date_day.day_number = 1 AND date_day.month_number = 10 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'ATLANTA' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: what are the five most frequently prescribed drugs for patients that had previously received endotracheal tube removal within the same hospital visit,? ### Response:
SELECT t3.drugname FROM (SELECT t2.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'endotracheal tube removal') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.drugstarttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 5
### Instruction: show me flights from LOS ANGELES to PITTSBURGH for tuesday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PITTSBURGH' AND date_day.day_number = 22 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'LOS ANGELES' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: was the value of the creatinine of patient 2334 last measured on the first hospital visit greater than that second to last measured on the first hospital visit? ### Response:
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 2334 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'creatinine') ORDER BY labevents.charttime DESC LIMIT 1) > (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 2334 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'creatinine') ORDER BY labevents.charttime DESC LIMIT 1 OFFSET 1)
### Instruction: was the chloride value of patient 23930 second measured on the first hospital visit less than the value that was first measured on the first hospital visit. ### Response:
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 23930 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'chloride') ORDER BY labevents.charttime LIMIT 1 OFFSET 1) < (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 23930 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'chloride') ORDER BY labevents.charttime LIMIT 1)
### Instruction: count the number of people who were prescribed oxcarbazepine in the same month following a diagnosis of urin tract infection nos. ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, diagnoses_icd.charttime FROM diagnoses_icd JOIN admissions ON diagnoses_icd.hadm_id = admissions.hadm_id WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'urin tract infection nos')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'oxcarbazepine') AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND DATETIME(t1.charttime, 'start of month') = DATETIME(t2.startdate, 'start of month')
### Instruction: are there any flights from MILWAUKEE to TACOMA on friday 6 11 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'TACOMA' AND date_day.day_number = 11 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'MILWAUKEE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: Undeleted posts after the longest time. ### Response:
WITH Raw AS (SELECT MAX(DelHist.Id) AS DelHistId, UndelHist.Id AS UndelHistId, MAX(UndelHist.PostId) AS PostId, MAX(DelHist.CreationDate) AS DeletionDate, MAX(UndelHist.CreationDate) AS UndelDate, CAST((JULIANDAY(MAX(UndelHist.CreationDate)) - JULIANDAY(MAX(DelHist.CreationDate))) * 86400.0 AS INT) AS Seconds FROM PostHistory AS DelHist, PostHistory AS UndelHist WHERE UndelHist.PostHistoryTypeId = 13 AND DelHist.PostHistoryTypeId = 12 AND DelHist.PostId = UndelHist.PostId AND DelHist.Id < UndelHist.Id GROUP BY UndelHist.Id) SELECT PostId AS "post_link", 'site://posts/' + CAST(PostId AS TEXT) + '/revisions' AS HistoryLink, * FROM Raw ORDER BY Seconds DESC, PostId LIMIT 100
### Instruction: what difference is in the mcv value of patient 25493 second measured on the last hospital visit compared to the value first measured on the last hospital visit? ### Response:
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25493 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'mcv') ORDER BY labevents.charttime LIMIT 1 OFFSET 1) - (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25493 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'mcv') ORDER BY labevents.charttime LIMIT 1)
### Instruction: please list all the flights from CHICAGO to KANSAS CITY on 6 17 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'KANSAS CITY' AND date_day.day_number = 17 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'CHICAGO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: please give me the flights from KANSAS CITY to CHICAGO on 6 16 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'CHICAGO' AND date_day.day_number = 16 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'KANSAS CITY' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: how many patients were prescribed plavix in the same hospital encounter since 2102 after being diagnosed with encephalopathy? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'encephalopathy' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2102') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'plavix' AND STRFTIME('%y', medication.drugstarttime) >= '2102') AS t2 WHERE t1.diagnosistime < t2.drugstarttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
### Instruction: i'd like flight information from DALLAS FORT WORTH to BOSTON on tuesday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BOSTON' AND date_day.day_number = 22 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DALLAS FORT WORTH' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: what are the four year survival rates for hepatic dysfunction - chronic patients? ### Response:
SELECT SUM(CASE WHEN patient.hospitaldischargestatus = 'alive' THEN 1 WHEN STRFTIME('%j', patient.hospitaldischargetime) - STRFTIME('%j', t2.diagnosistime) > 4 * 365 THEN 1 ELSE 0 END) * 100 / COUNT(*) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'hepatic dysfunction - chronic' GROUP BY patient.uniquepid HAVING MIN(diagnosis.diagnosistime) = diagnosis.diagnosistime) AS t1 WHERE STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', t1.diagnosistime) > 4 * 365) AS t2 JOIN patient ON t2.uniquepid = patient.uniquepid
### Instruction: since 2105 how many patients were prescribed pantoprazole during the same hospital encounter after the procedure of beta blocker - esmolol. ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'beta blocker - esmolol' AND STRFTIME('%y', treatment.treatmenttime) >= '2105') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'pantoprazole' AND STRFTIME('%y', medication.drugstarttime) >= '2105') AS t2 WHERE t1.treatmenttime < t2.drugstarttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
### Instruction: Answers that took way too long to accept (single user). Answers that took the longest from being posted to being accepted. Only answers that are currently accepted are counted. This query is for a single user; for all users, see query 695493. ### Response:
SELECT Posts.Id AS "post_link", DATEDIFF(day, Posts.CreationDate, CreationDate) AS "time_taken_to_accept_in_days", ROUND(DATEDIFF(day, Posts.CreationDate, CreationDate) / 12.0, 0) AS "in_months", ROUND(DATEDIFF(day, Posts.CreationDate, CreationDate) / 365.0, 1) AS "and_in_years" FROM Posts JOIN Votes ON Posts.Id = Votes.PostId WHERE OwnerUserId = '##UserId##' AND Votes.VoteTypeId = 1 AND DATEDIFF(day, Posts.CreationDate, CreationDate) >= 365 * '##MinYears?1##' ORDER BY 'time_taken_to_accept_in_days' DESC
### Instruction: i want a flight from SAN FRANCISCO to DENVER leaving SAN FRANCISCO in the afternoon arriving DENVER around 5 in the afternoon ### 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 (((flight.arrival_time <= 1730 AND flight.arrival_time >= 1630) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DENVER' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SAN FRANCISCO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.departure_time BETWEEN 1200 AND 1800
### Instruction: what was the top three most common procedure that patients received within 2 months after having received a inferior vena cava filter procedure? ### Response:
SELECT t3.treatmentname FROM (SELECT t2.treatmentname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'inferior vena cava filter') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t2.treatmenttime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month') GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 3
### Instruction: i would like a flight from BOSTON to SAN FRANCISCO on 8 17 ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND date_day.day_number = 17 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: show me one way flights from INDIANAPOLIS to MEMPHIS before 1000 on any day ### 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, fare, flight, flight_fare WHERE ((fare.round_trip_required = 'NO' AND flight_fare.fare_id = fare.fare_id AND flight.departure_time < 1000 AND flight.flight_id = flight_fare.flight_id) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'MEMPHIS' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'INDIANAPOLIS' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: What percentile am I in for a given tag for a given location?. Determines where you rank in a given tag as of the last data load ### Response:
SELECT STR(NTILE(100) OVER (ORDER BY SUM(answers.Score) DESC), 3) + '%' AS "top", ROW_NUMBER() OVER (ORDER BY SUM(answers.Score) DESC) AS "ranking", Users.Id AS "user_link", SUM(answers.Score) AS "total_score" FROM Tags JOIN PostTags ON Tags.Id = PostTags.TagId AND Tags.TagName = '##TagName##' JOIN Posts AS questions ON questions.Id = PostTags.PostId AND questions.CommunityOwnedDate IS NULL JOIN Posts AS answers ON answers.ParentId = questions.Id AND answers.Score != 0 AND NOT answers.OwnerUserId IS NULL AND answers.CommunityOwnedDate IS NULL JOIN Users ON answers.OwnerUserId = Users.Id WHERE LOWER(Location) LIKE LOWER('%##location##%') GROUP BY Users.Id ORDER BY CASE Users.Id WHEN '##UserId##' THEN 1 ELSE 0 END DESC, 'total_score' DESC
### Instruction: how many patients who received oral hypoglycemic administration procedure within 2 months after receiving a non-invasive ventilation procedure in 2102? ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'non-invasive ventilation' AND STRFTIME('%y', treatment.treatmenttime) = '2102') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'oral hypoglycemic administration' AND STRFTIME('%y', treatment.treatmenttime) = '2102') AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t2.treatmenttime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month')
### Instruction: find a flight from WASHINGTON to SAN FRANCISCO on tuesday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND date_day.day_number = 22 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'WASHINGTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: list all flights from BALTIMORE to SAN FRANCISCO on friday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND date_day.day_number = 25 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BALTIMORE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: flights from NEWARK to TAMPA on friday on US ### 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, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'TAMPA' AND date_day.day_number = 25 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'NEWARK' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'US'
### Instruction: show me all flights from SAN DIEGO to PHOENIX on a BOEING 737 ### Response:
SELECT DISTINCT flight.flight_id FROM aircraft, airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, equipment_sequence, flight WHERE (aircraft.basic_type = '737' AND aircraft.manufacturer = 'BOEING' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHOENIX' AND equipment_sequence.aircraft_code = aircraft.aircraft_code AND flight.aircraft_code_sequence = equipment_sequence.aircraft_code_sequence AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SAN DIEGO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: Things you have to learn. ### Response:
WITH PostMonth AS (SELECT DATEFROMPARTS(TIME_TO_STR(CreationDate, '%Y'), TIME_TO_STR(CreationDate, '%M'), 1) AS Month, COUNT(*) AS Count FROM Posts WHERE PostTypeId = 1 GROUP BY DATEFROMPARTS(TIME_TO_STR(CreationDate, '%Y'), TIME_TO_STR(CreationDate, '%M'), 1)), TopTags AS (SELECT Id FROM Tags WHERE Count > '##MinTagCount:int?10##') SELECT DATEFROMPARTS(TIME_TO_STR(Posts.CreationDate, '%Y'), TIME_TO_STR(Posts.CreationDate, '%M'), 1) AS Month, PostTags.TagId, COUNT(*) AS Count FROM Posts, PostTags, TopTags WHERE PostTags.TagId = TopTags.Id AND Posts.Id = PostTags.PostId GROUP BY DATEFROMPARTS(TIME_TO_STR(Posts.CreationDate, '%Y'), TIME_TO_STR(Posts.CreationDate, '%M'), 1), PostTags.TagId ORDER BY Month, PostTags.TagId
### Instruction: what is the three year survival probability, among the patients diagnosed with interstitial lung disease? ### Response:
SELECT SUM(CASE WHEN patient.hospitaldischargestatus = 'alive' THEN 1 WHEN STRFTIME('%j', patient.hospitaldischargetime) - STRFTIME('%j', t2.diagnosistime) > 3 * 365 THEN 1 ELSE 0 END) * 100 / COUNT(*) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'interstitial lung disease' GROUP BY patient.uniquepid HAVING MIN(diagnosis.diagnosistime) = diagnosis.diagnosistime) AS t1 WHERE STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', t1.diagnosistime) > 3 * 365) AS t2 JOIN patient ON t2.uniquepid = patient.uniquepid
### Instruction: i'm in MIAMI and i'd like to travel to LAS VEGAS on sunday ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'LAS VEGAS' AND date_day.day_number = 27 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'MIAMI' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: what is the top three most frequent microbiology tests that followed in the same month for patients who received chest x-ray? ### Response:
SELECT t3.culturesite FROM (SELECT t2.culturesite, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'chest x-ray') AS t1 JOIN (SELECT patient.uniquepid, microlab.culturesite, microlab.culturetakentime FROM microlab JOIN patient ON microlab.patientunitstayid = patient.patientunitstayid) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.culturetakentime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.culturetakentime, 'start of month') GROUP BY t2.culturesite) AS t3 WHERE t3.c1 <= 3
### Instruction: i need a flight from PITTSBURGH to BOSTON on wednesday the fourteenth ### 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, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BOSTON' AND date_day.day_number = 23 AND date_day.month_number = 4 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: Number of posts per one active user. ### Response:
WITH counts_cte AS (SELECT LAST_DATE_OF_MONTH(p.CreationDate) AS Cmonth, COUNT(p.Id) AS "total_posts", SUM(CASE WHEN p.PostTypeId = 1 THEN 1 ELSE 0 END) AS QCount, SUM(CASE WHEN p.PostTypeId = 2 THEN 1 ELSE 0 END) AS ACount FROM Posts AS p GROUP BY LAST_DATE_OF_MONTH(p.CreationDate)), usercounts_cte AS (SELECT LAST_DATE_OF_MONTH(p.CreationDate) AS Umonth, CAST(COUNT(DISTINCT p.OwnerUserId) + COUNT(DISTINCT p.OwnerDisplayName) AS INT) AS UCount FROM Posts AS p GROUP BY LAST_DATE_OF_MONTH(p.CreationDate)) SELECT Cmonth, ACount, UCount, (CAST(ACount AS FLOAT)) / (CAST(UCount AS FLOAT)) AS "answers_per_user" FROM counts_cte INNER JOIN usercounts_cte ON Cmonth = Umonth ORDER BY Cmonth
### Instruction: find travel arrangements for a round trip flight from DALLAS to PITTSBURGH after 2000 ### 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, fare, flight, flight_fare WHERE ((NOT fare.round_trip_cost IS NULL AND flight_fare.fare_id = fare.fare_id AND flight.departure_time > 2000 AND flight.flight_id = flight_fare.flight_id) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PITTSBURGH' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DALLAS' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: is patient 18237's chloride value second measured on the first hospital visit greater than it was first measured on the first hospital visit? ### Response:
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 18237 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'chloride') ORDER BY labevents.charttime LIMIT 1 OFFSET 1) > (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 18237 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'chloride') ORDER BY labevents.charttime LIMIT 1)
### Instruction: exactly what has the change in the anion gap of patient 26156 last measured on the first hospital visit compared to the value first measured on the first hospital visit? ### Response:
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 26156 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'anion gap') ORDER BY labevents.charttime DESC LIMIT 1) - (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 26156 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'anion gap') ORDER BY labevents.charttime LIMIT 1)