instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: how much is patient 28447's changing heart rate last measured on the current icu visit compared to the value first measured on the current icu visit? ### Response:
SELECT (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 = 28447) AND icustays.outtime IS NULL) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'heart rate' AND d_items.linksto = 'chartevents') ORDER BY chartevents.charttime DESC LIMIT 1) - (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 = 28447) AND icustays.outtime IS NULL) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'heart rate' AND d_items.linksto = 'chartevents') ORDER BY chartevents.charttime LIMIT 1)
### Instruction: what are the five most commonly given microbiology tests for patients that had previously received insulin - sliding scale administration during the same month until 2 years ago? ### 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 = 'insulin - sliding scale administration' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, microlab.culturesite, microlab.culturetakentime FROM microlab JOIN patient ON microlab.patientunitstayid = patient.patientunitstayid WHERE DATETIME(microlab.culturetakentime) <= DATETIME(CURRENT_TIME(), '-2 year')) 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 <= 5
### Instruction: how many people had died after being diagnosed with ventltr assoc pneumonia during the same hospital encounter in 2103? ### Response:
SELECT COUNT(DISTINCT t2.subject_id) FROM (SELECT t1.subject_id, t1.charttime, t1.hadm_id FROM (SELECT admissions.subject_id, diagnoses_icd.charttime, admissions.hadm_id 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 = 'ventltr assoc pneumonia')) AS t1 GROUP BY t1.subject_id HAVING MIN(t1.charttime) = t1.charttime AND STRFTIME('%y', t1.charttime) = '2103') AS t2 JOIN (SELECT patients.subject_id, admissions.hadm_id, patients.dod FROM admissions JOIN patients ON patients.subject_id = admissions.subject_id WHERE NOT patients.dod IS NULL AND STRFTIME('%y', patients.dod) = '2103') AS t3 ON t2.subject_id = t3.subject_id WHERE t2.hadm_id = t3.hadm_id
### Instruction: for the last time this month, when was patient 016-24379 prescribed heparin sod (porcine) and magnesium sulfate ivpb at the same time? ### Response:
SELECT t1.drugstarttime FROM (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'heparin sod (porcine)' AND patient.uniquepid = '016-24379' AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month')) AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'magnesium sulfate ivpb' AND patient.uniquepid = '016-24379' AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) ORDER BY t1.drugstarttime DESC LIMIT 1
### Instruction: when did patient 021-213732 last get prescribed for percocet 5/325 tab and pantoprazole at the same time the last month? ### Response:
SELECT t1.drugstarttime FROM (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'percocet 5/325 tab' AND patient.uniquepid = '021-213732' AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')) AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'pantoprazole' AND patient.uniquepid = '021-213732' AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) ORDER BY t1.drugstarttime DESC LIMIT 1
### Instruction: what is the top four most frequently prescribed drugs that were prescribed to patients in the same month after being diagnosed with encephalopathy - metabolic since 3 years ago? ### Response:
SELECT t3.drugname FROM (SELECT t2.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'encephalopathy - metabolic' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-3 year')) AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-3 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.drugstarttime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.drugstarttime, 'start of month') GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 4
### Instruction: what is the variation in the weight of patient 15447 last measured on the current hospital visit compared to the value first measured on the current hospital visit? ### Response:
SELECT (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 = 15447 AND admissions.dischtime IS NULL)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'admit wt' AND d_items.linksto = 'chartevents') ORDER BY chartevents.charttime DESC LIMIT 1) - (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 = 15447 AND admissions.dischtime IS NULL)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'admit wt' AND d_items.linksto = 'chartevents') ORDER BY chartevents.charttime LIMIT 1)
### Instruction: what kind of aircraft does DL fly before 800 on 8 2 from BOSTON to DENVER ### 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, date_day, days, equipment_sequence, flight WHERE (((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.departure_time < 800 AND flight.flight_days = days.days_code) 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 = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) 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 were the five most frequent microbiological tests that followed within 2 months for patients who received glucose - d50 since 2101? ### 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 = 'glucose - d50' AND STRFTIME('%y', treatment.treatmenttime) >= '2101') AS t1 JOIN (SELECT patient.uniquepid, microlab.culturesite, microlab.culturetakentime FROM microlab JOIN patient ON microlab.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', microlab.culturetakentime) >= '2101') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.culturetakentime AND DATETIME(t2.culturetakentime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month') GROUP BY t2.culturesite) AS t3 WHERE t3.c1 <= 5
### Instruction: Post Metrics Over Year and Month. ### Response:
SELECT TIME_TO_STR(P.CreationDate, '%YEAR') AS PostYear, TIME_TO_STR(P.CreationDate, '%-mONT%-H') AS PostMonth, COUNT(*) AS Posts, SUM(AnswerCount) AS AnswerSum, SUM(CommentCount) AS CommentSum, MIN(FavoriteCount) AS FavoriteMin, AVG(FavoriteCount) AS FavoriteAvg, MAX(FavoriteCount) AS FavoriteMax, SUM(FavoriteCount) AS FavoriteSum, MIN(Score) AS ScoreMin, AVG(Score) AS ScoreAvg, MAX(Score) AS ScoreMax, SUM(Score) AS ScoreSum, MIN(ViewCount) AS ViewMin, AVG(ViewCount) AS ViewAvg, MAX(ViewCount) AS ViewMax, SUM(ViewCount) AS ViewSum FROM Posts AS P WHERE P.CreationDate BETWEEN '2008-08-01' AND '2015-08-01' GROUP BY TIME_TO_STR(P.CreationDate, '%YEAR'), TIME_TO_STR(P.CreationDate, '%-mONT%-H') ORDER BY TIME_TO_STR(P.CreationDate, '%YEAR'), TIME_TO_STR(P.CreationDate, '%-mONT%-H')
### Instruction: what were the top four most frequent specimen tests given to patients within the same month after the diagnosis of facial bone fracture in 2105? ### Response:
SELECT t3.culturesite FROM (SELECT t2.culturesite, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'facial bone fracture' AND STRFTIME('%y', diagnosis.diagnosistime) = '2105') AS t1 JOIN (SELECT patient.uniquepid, microlab.culturesite, microlab.culturetakentime FROM microlab JOIN patient ON microlab.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', microlab.culturetakentime) = '2105') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.culturetakentime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.culturetakentime, 'start of month') GROUP BY t2.culturesite) AS t3 WHERE t3.c1 <= 4
### Instruction: what was the top four most common procedure that patients received during the same month after having received a exploratory laparoscopy procedure a year before? ### 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 = 'exploratory laparoscopy' AND DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month') GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 4
### Instruction: what are the four most common lab tests ordered for patients who were previously diagnosed with coagulopathy - coagulation factor deficiency syndrome within 2 months, in 2105? ### Response:
SELECT t3.labname FROM (SELECT t2.labname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'coagulopathy - coagulation factor deficiency syndrome' AND STRFTIME('%y', diagnosis.diagnosistime) = '2105') AS t1 JOIN (SELECT patient.uniquepid, lab.labname, lab.labresulttime FROM lab JOIN patient ON lab.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', lab.labresulttime) = '2105') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.labresulttime AND DATETIME(t2.labresulttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month') GROUP BY t2.labname) AS t3 WHERE t3.c1 <= 4
### Instruction: count the number of patients who were diagnosed with intracranial injury - with concussion until 2104 and did not return to the hospital within the same month. ### Response:
SELECT (SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'intracranial injury - with concussion' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2104') AS t1) - (SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'intracranial injury - with concussion' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2104') AS t2 JOIN patient ON t2.uniquepid = patient.uniquepid WHERE t2.diagnosistime < patient.hospitaladmittime AND STRFTIME('%y', patient.hospitaladmittime) <= '2104' AND DATETIME(t2.diagnosistime, 'start of month') = DATETIME(patient.hospitaladmittime, 'start of month'))
### Instruction: what were the top three most commonly performed procedures that patients received in the same hospital visit after diagnosis of hyperglycemia - suspected since 5 years ago? ### Response:
SELECT t3.treatmentname FROM (SELECT t2.treatmentname, 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 = 'hyperglycemia - suspected' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-5 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-5 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.treatmenttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 3
### Instruction: since 2 years ago, what were the top three most frequently ordered lab tests for patients during the same hospital encounter after the diagnosis of intra-abdominal abscess - intestinal? ### Response:
SELECT t3.labname FROM (SELECT t2.labname, 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 = 'intra-abdominal abscess - intestinal' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, lab.labname, lab.labresulttime, patient.patienthealthsystemstayid FROM lab JOIN patient ON lab.patientunitstayid = patient.patientunitstayid WHERE DATETIME(lab.labresulttime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.labresulttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.labname) AS t3 WHERE t3.c1 <= 3
### Instruction: what were the four most common drugs that were prescribed to patients during the same month after they were prescribed with heparin (preservative free) during this year? ### Response:
SELECT t3.drug FROM (SELECT t2.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'heparin (preservative free)' AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.drug, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.startdate < t2.startdate AND DATETIME(t1.startdate, 'start of month') = DATETIME(t2.startdate, 'start of month') GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 4
### Instruction: list nonstop flights from BALTIMORE WASHINGTON to OAKLAND that arrive between 1645 and 1715 ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, airport_service AS AIRPORT_SERVICE_2, city AS CITY_0, city AS CITY_1, city AS CITY_2, flight WHERE (((flight.arrival_time <= 1715 AND flight.arrival_time >= 1645) AND CITY_2.city_code = AIRPORT_SERVICE_2.city_code AND CITY_2.city_name = 'OAKLAND' AND flight.to_airport = AIRPORT_SERVICE_2.airport_code) AND ((flight.from_airport = AIRPORT_SERVICE_0.airport_code AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BALTIMORE') OR (flight.from_airport = AIRPORT_SERVICE_1.airport_code AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'WASHINGTON'))) AND flight.stops = 0
### Instruction: what were the top four most frequent diagnoses given to patients during the same hospital encounter after receiving glycoprotein iib/iiia inhibitor until 2102? ### 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 = 'glycoprotein iib/iiia inhibitor' AND STRFTIME('%y', treatment.treatmenttime) <= '2102') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', diagnosis.diagnosistime) <= '2102') 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: what are the flights which depart from SAN FRANCISCO fly to WASHINGTON via INDIANAPOLIS and arrive by 2100 ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, airport_service AS AIRPORT_SERVICE_2, city AS CITY_0, city AS CITY_1, city AS CITY_2, flight, flight_stop WHERE ((CITY_2.city_code = AIRPORT_SERVICE_2.city_code AND CITY_2.city_name = 'INDIANAPOLIS' AND flight_stop.stop_airport = AIRPORT_SERVICE_2.airport_code AND flight.arrival_time <= 2100 AND flight.flight_id = flight_stop.flight_id) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'WASHINGTON' 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: please show me flights from PITTSBURGH to ATLANTA on wednesday morning serving BREAKFAST ### 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, food_service WHERE (((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 food_service.meal_code = flight.meal_code AND food_service.meal_description = 'BREAKFAST') AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ATLANTA' 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.departure_time BETWEEN 0 AND 1200
### Instruction: show me the four year survival rate of patients who were prescribed buminate after they were diagnosed with dementia? ### Response:
SELECT SUM(CASE WHEN patient.hospitaldischargestatus = 'alive' THEN 1 WHEN STRFTIME('%j', patient.hospitaldischargetime) - STRFTIME('%j', t4.diagnosistime) > 4 * 365 THEN 1 ELSE 0 END) * 100 / COUNT(*) FROM (SELECT t2.uniquepid, t2.diagnosistime FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'dementia' GROUP BY patient.uniquepid HAVING MIN(diagnosis.diagnosistime) = diagnosis.diagnosistime) AS t1) AS t2 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'buminate') AS t3 ON t2.uniquepid = t3.uniquepid WHERE t2.diagnosistime < t3.drugstarttime) AS t4 JOIN patient ON t4.uniquepid = patient.uniquepid
### Instruction: what were the top three most common procedures that followed within 2 months for patients who had antifungal therapy - fluconazole until 1 year ago? ### 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 = 'antifungal therapy - fluconazole' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-1 year')) 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: is there an airline that has a flight from PHILADELPHIA to SAN FRANCISCO with a stop in DALLAS ### Response:
SELECT DISTINCT airline.airline_code FROM airline, airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, airport_service AS AIRPORT_SERVICE_2, city AS CITY_0, city AS CITY_1, city AS CITY_2, flight, flight_stop WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND CITY_2.city_code = AIRPORT_SERVICE_2.city_code AND CITY_2.city_name = 'DALLAS' AND flight_stop.stop_airport = AIRPORT_SERVICE_2.airport_code AND flight.flight_id = flight_stop.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 = 'PHILADELPHIA' AND flight.airline_code = airline.airline_code AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: this year, what were the top three most frequent procedures that patients received in the same month after receiving a antiemetic - promethazine? ### 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 = 'antiemetic - promethazine' AND DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month') GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 3
### Instruction: since 4 years ago, how many patients were prescribed with dextrose 5% within 2 months after diagnosed with septicemia 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 = 'septicemia nos') AND DATETIME(diagnoses_icd.charttime) >= DATETIME(CURRENT_TIME(), '-4 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'dextrose 5%' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-4 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND DATETIME(t2.startdate) BETWEEN DATETIME(t1.charttime) AND DATETIME(t1.charttime, '+2 month')
### Instruction: until 2 years ago, what are the three most frequent diagnoses that patients were given within 2 months after receiving antidiarrhea agent? ### Response:
SELECT t3.diagnosisname FROM (SELECT t2.diagnosisname, 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 = 'antidiarrhea agent' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.diagnosistime AND DATETIME(t2.diagnosistime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month') GROUP BY t2.diagnosisname) AS t3 WHERE t3.c1 <= 3
### Instruction: Votes in a tag per day. Show a daily breakdown of the number of upvotes (+) and downvotes (-) on questions (Q) and answers (+) in a given tag. The data is based on the question tags at the time the query is run, not on the tags at the time of the vote. The total column includes all types of votes (not just up/down but also favorite, close/reopen, etc.). ### Response:
SELECT v.CreationDate AS "date", COUNT(CASE WHEN v.VoteTypeId = 2 AND p.PostTypeId = 1 THEN 1 ELSE NULL END) AS "q+", COUNT(CASE WHEN v.VoteTypeId = 3 AND p.PostTypeId = 1 THEN 1 ELSE NULL END) AS "q-", COUNT(CASE WHEN v.VoteTypeId = 2 AND p.PostTypeId = 2 THEN 1 ELSE NULL END) AS "a+", COUNT(CASE WHEN v.VoteTypeId = 3 AND p.PostTypeId = 2 THEN 1 ELSE NULL END) AS "a-", COUNT(*) AS "total" FROM Votes AS v INNER JOIN Posts AS p ON p.Id = v.PostId INNER JOIN Posts AS q ON q.Id = p.Id OR q.Id = p.ParentId WHERE q.PostTypeId = 1 AND (q.Tags LIKE '%<##Tag##>%' OR q.Tags LIKE '% ##Tag## %') GROUP BY v.CreationDate ORDER BY Date
### Instruction: what are the top three most common diagnoses that patients have had within the same month after receiving vasopressors - phenylephrine (neosynephrine) since 2105. ### Response:
SELECT t3.diagnosisname FROM (SELECT t2.diagnosisname, 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 = 'vasopressors - phenylephrine (neosynephrine)' AND STRFTIME('%y', treatment.treatmenttime) >= '2105') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', diagnosis.diagnosistime) >= '2105') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.diagnosistime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.diagnosistime, 'start of month') GROUP BY t2.diagnosisname) AS t3 WHERE t3.c1 <= 3
### Instruction: what are the four most common diagnostics for people who were diagnosed with metabolic alkalosis earlier within the same hospital visit, until 2104? ### Response:
SELECT t3.diagnosisname FROM (SELECT t2.diagnosisname, 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 = 'metabolic alkalosis' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2104') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', diagnosis.diagnosistime) <= '2104') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.diagnosistime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.diagnosisname) AS t3 WHERE t3.c1 <= 4
### Instruction: what was the five most frequently ordered laboratory tests for patients who had already been diagnosed with cardiac arrest - un-witnessed in the same hospital encounter, until 1 year ago? ### Response:
SELECT t3.labname FROM (SELECT t2.labname, 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 = 'cardiac arrest - un-witnessed' AND DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t1 JOIN (SELECT patient.uniquepid, lab.labname, lab.labresulttime, patient.patienthealthsystemstayid FROM lab JOIN patient ON lab.patientunitstayid = patient.patientunitstayid WHERE DATETIME(lab.labresulttime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.labresulttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.labname) AS t3 WHERE t3.c1 <= 5
### Instruction: list the five most frequent drugs that were prescribed to patients during the same hospital encounter after having been prescribed with fenofibrate micronized during a year before? ### Response:
SELECT t3.drug FROM (SELECT t2.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, prescriptions.startdate, admissions.hadm_id FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'fenofibrate micronized' AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.drug, prescriptions.startdate, admissions.hadm_id FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.startdate < t2.startdate AND t1.hadm_id = t2.hadm_id GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 5
### Instruction: what were the three most frequent drugs prescribed during the same month to the peripheral vascular ischemia - with claudication female patients of age 40s after they had been diagnosed with peripheral vascular ischemia - with claudication,. ### Response:
SELECT t3.drugname FROM (SELECT t2.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'peripheral vascular ischemia - with claudication') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE patient.gender = 'female' AND patient.age BETWEEN 40 AND 49) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.drugstarttime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.drugstarttime, 'start of month') GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 3
### Instruction: at least 1 of the following: a ) capillary glycated hemoglobin 5.7 _ 6.4 % , b ) fasting capillary glucose 100 _ 125 mg / dl, or c ) capillary glycated hemoglobin < 5.7 % and borderline fasting capillary glucose level 95 _ 99 mg / dl and a subsequent fasting venous plasma glucose 100 _ 125 mg / dl ### Response:
SELECT * FROM table_train_244 WHERE (CASE WHEN capillary_glycated_hemoglobin >= 5.7 AND capillary_glycated_hemoglobin <= 6.4 THEN 1 ELSE 0 END + CASE WHEN fasting_capillary_glucose >= 100 AND fasting_capillary_glucose <= 125 THEN 1 ELSE 0 END + CASE WHEN capillary_glycated_hemoglobin < 5.7 AND borderline_fasting_capillary_glucose_level >= 95 AND borderline_fasting_capillary_glucose_level <= 99 AND fasting_venous_plasma_glucose >= 100 AND fasting_venous_plasma_glucose <= 125 THEN 1 ELSE 0 END) >= 1
### Instruction: count the number of people who were prescribed 5% dextrose within the same month following a diagnosis of helicobacter pylori since 3 years ago. ### 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 = 'helicobacter pylori') AND DATETIME(diagnoses_icd.charttime) >= DATETIME(CURRENT_TIME(), '-3 year')) 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' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-3 year')) 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 the three most frequent drugs prescribed to the patients with the age of 60 or above during the same hospital encounter after they were diagnosed with alcoh dep nec/nos-contin? ### Response:
SELECT t3.drug FROM (SELECT t2.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, diagnoses_icd.charttime, admissions.hadm_id 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 = 'alcoh dep nec/nos-contin')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.drug, prescriptions.startdate, admissions.hadm_id FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE admissions.age >= 60) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND t1.hadm_id = t2.hadm_id GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 3
### Instruction: list the five most frequent diagnoses that patients have been diagnosed with in the same hospital encounter after undergoing electrolyte administration since 6 years ago. ### 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 = 'electrolyte administration' AND DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-6 year')) AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-6 year')) 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 <= 5
### Instruction: Explainer Refiner Illuminator Badge Progress. These badges are awarded based on the number of questions both edited and answered within 12 hours where the answer score is positive. Edited questions with multiple positive score answers only get counted once. ### Response:
SELECT CASE WHEN edits >= 1 THEN 'Yes' ELSE CONCAT(edits, '/', 1) END AS Explainer, CASE WHEN edits >= 50 THEN 'Yes' ELSE CONCAT(edits, '/', 50) END AS Refiner, CASE WHEN edits >= 500 THEN 'Yes' ELSE CONCAT(edits, '/', 500) END AS Illuminator FROM (SELECT COUNT(DISTINCT q.Id) AS edits FROM Posts AS a JOIN Posts AS q ON q.Id = a.ParentId AND q.PostTypeId = 1 AND q.ClosedDate IS NULL AND (q.OwnerUserId != '##UserId##' OR q.OwnerUserId IS NULL) JOIN PostHistory AS ph ON ph.PostId = a.ParentId AND ph.PostHistoryTypeId IN (4, 5) AND ph.UserId = '##UserId##' AND ABS(CAST((JULIANDAY(CreationDate) - JULIANDAY(ph.CreationDate)) AS INT)) <= 12 WHERE a.OwnerUserId = '##UserId##' AND a.PostTypeId = 2 AND a.Score >= 1) AS x
### Instruction: what were the top five most frequent drugs that patients were prescribed in the same month after having been prescribed with nystatin oral suspension the last year? ### Response:
SELECT t3.drug FROM (SELECT t2.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'nystatin oral suspension' AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.drug, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.startdate < t2.startdate AND DATETIME(t1.startdate, 'start of month') = DATETIME(t2.startdate, 'start of month') GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 5
### Instruction: what were the three most often used procedures for patients who had previously been diagnosed with s/p oral surgery procedure within 2 months, since 2105? ### Response:
SELECT t3.treatmentname FROM (SELECT t2.treatmentname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 's/p oral surgery procedure' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2105') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) >= '2105') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.treatmenttime AND DATETIME(t2.treatmenttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month') GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 3
### Instruction: how many patients underwent coronar arteriogr-2 cath after having been diagnosed with long-term use anticoagul within the same month? ### 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 = 'long-term use anticoagul')) AS t1 JOIN (SELECT admissions.subject_id, procedures_icd.charttime 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 = 'coronar arteriogr-2 cath')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.charttime AND DATETIME(t1.charttime, 'start of month') = DATETIME(t2.charttime, 'start of month')
### Instruction: what are the top five most frequent microbiology tests that patients were given in the same hospital encounter after receiving chest x-ray in 2104? ### Response:
SELECT t3.culturesite FROM (SELECT t2.culturesite, 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 = 'chest x-ray' AND STRFTIME('%y', treatment.treatmenttime) = '2104') AS t1 JOIN (SELECT patient.uniquepid, microlab.culturesite, microlab.culturetakentime, patient.patienthealthsystemstayid FROM microlab JOIN patient ON microlab.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', microlab.culturetakentime) = '2104') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.culturetakentime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.culturesite) AS t3 WHERE t3.c1 <= 5
### Instruction: when was the last time patient 007-9853 had been prescribed senna-docusate and chlorhexidine gluconate ud liq 15ml at the same time in 10/2102? ### Response:
SELECT t1.drugstarttime FROM (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'senna-docusate' AND patient.uniquepid = '007-9853' AND STRFTIME('%y-%m', medication.drugstarttime) = '2102-10') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'chlorhexidine gluconate ud liq 15ml' AND patient.uniquepid = '007-9853' AND STRFTIME('%y-%m', medication.drugstarttime) = '2102-10') AS t2 ON t1.uniquepid = t2.uniquepid WHERE DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) ORDER BY t1.drugstarttime DESC LIMIT 1
### Instruction: what are the three most commonly diagnosed diagnoses for patients who had previously received plasmapheresis - plasma exchange within 2 months in 2104? ### Response:
SELECT t3.diagnosisname FROM (SELECT t2.diagnosisname, 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 = 'plasmapheresis - plasma exchange' AND STRFTIME('%y', treatment.treatmenttime) = '2104') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', diagnosis.diagnosistime) = '2104') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.diagnosistime AND DATETIME(t2.diagnosistime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month') GROUP BY t2.diagnosisname) AS t3 WHERE t3.c1 <= 3
### Instruction: until 3 years ago how many patients were prescribed with metoprolol in the same hospital visit after they had undergone 1 int mam-cor art bypass? ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, procedures_icd.charttime, admissions.hadm_id 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 = '1 int mam-cor art bypass') AND DATETIME(procedures_icd.charttime) <= DATETIME(CURRENT_TIME(), '-3 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate, admissions.hadm_id FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'metoprolol' AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-3 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND t1.hadm_id = t2.hadm_id
### Instruction: for patients who have received endotracheal tube removal since 2 years ago, what are the top four most common medications that have followed during 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' AND DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-2 year')) 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 <= 4
### Instruction: what were the four most commonly prescribed drugs for patients until 2 years ago who were also prescribed with levofloxacin in d5w 500 mg/100ml iv soln at the same time? ### Response:
SELECT t3.drugname FROM (SELECT t2.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'levofloxacin in d5w 500 mg/100ml iv soln' AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 4
### Instruction: how many patients were prescribed with ns within the same month last year after the diagnosis with assault 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 = 'assault nos') AND DATETIME(diagnoses_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'ns' AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) 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: do you have any airlines that would stop at DENVER on the way from BALTIMORE to SAN FRANCISCO ### Response:
SELECT DISTINCT airline.airline_code FROM airline, airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, airport_service AS AIRPORT_SERVICE_2, city AS CITY_0, city AS CITY_1, city AS CITY_2, flight, flight_stop WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND CITY_2.city_code = AIRPORT_SERVICE_2.city_code AND CITY_2.city_name = 'DENVER' AND flight_stop.stop_airport = AIRPORT_SERVICE_2.airport_code AND flight.flight_id = flight_stop.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.airline_code = airline.airline_code AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: what are the three most commonly ordered laboratory tests for patients who have already been diagnosed with atelectasis/collapse - focal during the same hospital encounter, until 3 years ago? ### Response:
SELECT t3.labname FROM (SELECT t2.labname, 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 = 'atelectasis/collapse - focal' AND DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-3 year')) AS t1 JOIN (SELECT patient.uniquepid, lab.labname, lab.labresulttime, patient.patienthealthsystemstayid FROM lab JOIN patient ON lab.patientunitstayid = patient.patientunitstayid WHERE DATETIME(lab.labresulttime) <= DATETIME(CURRENT_TIME(), '-3 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.labresulttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.labname) AS t3 WHERE t3.c1 <= 3
### Instruction: count the number of people who were prescribed methadone hcl in the same hospital visit after having received a cont inv mec ven 96+ hrs procedure until 2102. ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, procedures_icd.charttime, admissions.hadm_id 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 = 'cont inv mec ven 96+ hrs') AND STRFTIME('%y', procedures_icd.charttime) <= '2102') AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate, admissions.hadm_id FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'methadone hcl' AND STRFTIME('%y', prescriptions.startdate) <= '2102') AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND t1.hadm_id = t2.hadm_id
### Instruction: what are the four most frequently prescribed drugs for patients who have been prescribed 37.5 g tube : dextrose (diabetic use) 40 % po gel also at the same time until 1 year ago? ### Response:
SELECT t3.drugname FROM (SELECT t2.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = '37.5 g tube : dextrose (diabetic use) 40 % po gel' AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 4
### Instruction: what were the top four most frequent diagnoses in 2105 with which patients were diagnosed after receiving a drug levels - serum drug levels within 2 months? ### Response:
SELECT t3.diagnosisname FROM (SELECT t2.diagnosisname, 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 = 'drug levels - serum drug levels' AND STRFTIME('%y', treatment.treatmenttime) = '2105') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', diagnosis.diagnosistime) = '2105') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.diagnosistime AND DATETIME(t2.diagnosistime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month') GROUP BY t2.diagnosisname) AS t3 WHERE t3.c1 <= 4
### Instruction: what is the four most commonly used procedures that were given to patients within 2 months after the diagnosis of ventricular fibrillation since 2104? ### Response:
SELECT t3.treatmentname FROM (SELECT t2.treatmentname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'ventricular fibrillation' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2104') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) >= '2104') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.treatmenttime AND DATETIME(t2.treatmenttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month') GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 4
### Instruction: in 2105, what were the four most frequent procedures that patients received in the same hospital encounter after the diagnosis of upper respiratory obstruction - suspected? ### Response:
SELECT t3.treatmentname FROM (SELECT t2.treatmentname, 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 = 'upper respiratory obstruction - suspected' AND STRFTIME('%y', diagnosis.diagnosistime) = '2105') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) = '2105') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.treatmenttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 4
### Instruction: what is the count of patients who were diagnosed with dmii wo cmp uncntrld in the same hospital visit after having been diagnosed with hypertension nos? ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, diagnoses_icd.charttime, admissions.hadm_id 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 = 'dmii wo cmp uncntrld')) AS t1 JOIN (SELECT admissions.subject_id, diagnoses_icd.charttime, admissions.hadm_id 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 = 'hypertension nos')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.charttime AND t1.hadm_id = t2.hadm_id
### Instruction: count the number of people who were prescribed tacrolimus within the same hospital visit following a diagnosis of pulm embol/infarct nec since 2105. ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, diagnoses_icd.charttime, admissions.hadm_id 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 = 'pulm embol/infarct nec') AND STRFTIME('%y', diagnoses_icd.charttime) >= '2105') AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate, admissions.hadm_id FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'tacrolimus' AND STRFTIME('%y', prescriptions.startdate) >= '2105') AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND t1.hadm_id = t2.hadm_id
### Instruction: list the top five most frequent drugs that the patients were prescribed with within 2 months after they were prescribed with zocor since 3 years ago. ### Response:
SELECT t3.drugname FROM (SELECT t2.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'zocor' AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-3 year')) AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-3 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.drugstarttime < t2.drugstarttime AND DATETIME(t2.drugstarttime) BETWEEN DATETIME(t1.drugstarttime) AND DATETIME(t1.drugstarttime, '+2 month') GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 5
### Instruction: list the four most frequent diagnoses that were given to patients in the same month after they were diagnosed with septic shock - gram positive organism until 2104. ### Response:
SELECT t3.diagnosisname FROM (SELECT t2.diagnosisname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'septic shock - gram positive organism' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2104') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', diagnosis.diagnosistime) <= '2104') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.diagnosistime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.diagnosistime, 'start of month') GROUP BY t2.diagnosisname) AS t3 WHERE t3.c1 <= 4
### Instruction: what were the top four most commonly performed procedures that patients took after being diagnosed with pleural effusion - bilateral in the same hospital visit until 2102? ### Response:
SELECT t3.treatmentname FROM (SELECT t2.treatmentname, 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 = 'pleural effusion - bilateral' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2102') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) <= '2102') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.treatmenttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 4
### Instruction: i would like to find a flight from PITTSBURGH to BOSTON on wednesday and i have to be in BOSTON by one so i'd like a flight out of here no later than 1100 ### 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 (((flight.arrival_time <= 1300 AND flight.departure_time <= 1100) 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 CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BOSTON' 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 was the top five most frequent laboratory tests given to patients after receiving a periph nerve div nec within 2 months? ### Response:
SELECT d_labitems.label FROM d_labitems WHERE d_labitems.itemid IN (SELECT t3.itemid FROM (SELECT t2.itemid, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, procedures_icd.charttime 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 = 'periph nerve div nec')) AS t1 JOIN (SELECT admissions.subject_id, labevents.itemid, labevents.charttime FROM labevents JOIN admissions ON labevents.hadm_id = admissions.hadm_id) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.charttime AND DATETIME(t2.charttime) BETWEEN DATETIME(t1.charttime) AND DATETIME(t1.charttime, '+2 month') GROUP BY t2.itemid) AS t3 WHERE t3.c1 <= 5)
### Instruction: what are the top three most frequent procedures that are followed within the same hospital visit for patients who received immunosuppressive therapy - tacrolimus in 2104? ### 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 = 'immunosuppressive therapy - tacrolimus' AND STRFTIME('%y', treatment.treatmenttime) = '2104') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) = '2104') 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 <= 3
### Instruction: Lists all users which answered the same questions as I did and compare the scores. Lists all users which answered the same questions as I did and compare the scores ### Response:
SELECT oa.OwnerUserId AS "user_link", COUNT(*) AS "total_answers", SUM(CASE WHEN AcceptedAnswerId = ma.Id THEN 1 ELSE 0 END) AS "ma_accepted", SUM(CASE WHEN AcceptedAnswerId = oa.Id THEN 1 ELSE 0 END) AS "oa_accepted", NULLIF(SUM(CASE WHEN AcceptedAnswerId = ma.Id THEN 1 ELSE 0 END), 0) / NULLIF(SUM(CASE WHEN AcceptedAnswerId = oa.Id THEN 1 ELSE 0 END), 0) * 100.0 AS "ratio", SUM(ma.Score) AS "ma_total_score", SUM(oa.Score) AS "oa_total_score", NULLIF(SUM(ma.Score), 0) / NULLIF(SUM(oa.Score), 0) * 100.0 AS "ratio" FROM Posts AS ma INNER JOIN Posts AS qu ON ma.ParentId = qu.Id INNER JOIN Posts AS oa ON qu.Id = oa.ParentId AND ma.Id != oa.Id WHERE ma.PostTypeId = 2 AND ma.OwnerUserId = '##UserId##' AND NOT oa.OwnerUserId IS NULL GROUP BY oa.OwnerUserId
### Instruction: what is the top five most common procedures that followed within the same hospital visit for patients who received fiberoptic colonoscopy - with chemocautery since 2102? ### 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 = 'fiberoptic colonoscopy - with chemocautery' AND STRFTIME('%y', treatment.treatmenttime) >= '2102') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) >= '2102') 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: what is the four most frequent procedures that patients have received within 2 months following a anticoagulant administration - factor xa inhibitor procedure until 2102? ### 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 = 'anticoagulant administration - factor xa inhibitor' AND STRFTIME('%y', treatment.treatmenttime) <= '2102') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) <= '2102') 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 <= 4
### Instruction: may i please see airlines and flight numbers from NEW YORK to TORONTO on the same date 6 17 also arriving in TORONTO before 1200 thank you ### Response:
SELECT DISTINCT airline.airline_code, flight.flight_number FROM airline, 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 ((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.arrival_time < 1200 AND flight.flight_days = days.days_code) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'TORONTO' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'NEW YORK' AND flight.airline_code = airline.airline_code AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: how many airlines fly from NEW YORK to LOS ANGELES by way of MILWAUKEE ### Response:
SELECT COUNT(DISTINCT airline.airline_code) FROM airline, airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, airport_service AS AIRPORT_SERVICE_2, city AS CITY_0, city AS CITY_1, city AS CITY_2, flight, flight_stop WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'LOS ANGELES' AND CITY_2.city_code = AIRPORT_SERVICE_2.city_code AND CITY_2.city_name = 'MILWAUKEE' AND flight_stop.stop_airport = AIRPORT_SERVICE_2.airport_code AND flight.flight_id = flight_stop.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 = 'NEW YORK' AND flight.airline_code = airline.airline_code AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
### Instruction: how many patients were prescribed levothyroxine sodium within 2 months since 2105 after the procedure of cath base invasv ep test. ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, procedures_icd.charttime 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 = 'cath base invasv ep test') AND STRFTIME('%y', procedures_icd.charttime) >= '2105') AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'levothyroxine sodium' AND STRFTIME('%y', prescriptions.startdate) >= '2105') AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND DATETIME(t2.startdate) BETWEEN DATETIME(t1.charttime) AND DATETIME(t1.charttime, '+2 month')
### Instruction: when was the first time when patient 31482 was prescribed phenylephrine hcl and albumin 5% (25g / 500ml) at the same time in this month? ### Response:
SELECT t1.startdate FROM (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'phenylephrine hcl' AND admissions.subject_id = 31482 AND DATETIME(prescriptions.startdate, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'albumin 5% (25g / 500ml)' AND admissions.subject_id = 31482 AND DATETIME(prescriptions.startdate, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month')) AS t2 ON t1.subject_id = t2.subject_id WHERE DATETIME(t1.startdate) = DATETIME(t2.startdate) ORDER BY t1.startdate LIMIT 1
### Instruction: what was the top four most frequent diagnoses that patients were given within the same hospital visit after receiving a digoxin until 2 years ago? ### 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 = 'digoxin' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-2 year')) 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: since 2105 what are the top four most common drugs prescribed to patients in the same hospital encounter after stress ulcer prophylaxis - famotidine? ### 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 = 'stress ulcer prophylaxis - famotidine' AND STRFTIME('%y', treatment.treatmenttime) >= '2105') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', medication.drugstarttime) >= '2105') 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 <= 4
### Instruction: what is the name of the drug patient 022-6959 was prescribed for during the same day after being diagnosed with pneumonia on the current hospital visit. ### Response:
SELECT t2.drugname FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '022-6959' AND patient.hospitaldischargetime IS NULL) AND diagnosis.diagnosisname = 'pneumonia') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '022-6959' AND patient.hospitaldischargetime IS NULL)) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.drugstarttime AND DATETIME(t1.diagnosistime, 'start of day') = DATETIME(t2.drugstarttime, 'start of day')
### Instruction: Decadist badge: Collected at least 200 rep from post votes in each year of the last 10. Not exact, we can't count a lot of things affecting the reputation, but it is about roughly this. Check this [meta discussion](https://meta.stackoverflow.com/q/374646/1783163). ### Response:
WITH VoteRep AS (SELECT 1 AS VoteTypeId, 2 AS PostTypeId, 15 AS Rep UNION SELECT 2 AS VoteTypeId, 1 AS PostTypeId, 5 AS Rep UNION SELECT 2 AS VoteTypeId, 2 AS PostTypeId, 10 AS Rep UNION SELECT 3 AS VoteTypeId, 1 AS PostTypeId, -2 AS Rep UNION SELECT 3 AS VoteTypeId, 2 AS PostTypeId, -2 AS Rep), Raw AS (SELECT VoteRep.Rep, Posts.OwnerUserId AS UserId, DATEDIFF(yy, Votes.CreationDate, CURRENT_TIMESTAMP()) AS Age FROM Posts, Votes, VoteRep WHERE Votes.PostId = Posts.Id AND Votes.VoteTypeId = VoteRep.VoteTypeId AND Posts.PostTypeId = VoteRep.PostTypeId) SELECT SUM(Rep) AS Rep, Age, UserId FROM Raw GROUP BY UserId, Age HAVING SUM(Rep) >= 200
### Instruction: how many patients died during the same month after being diagnosed in 2101 with hypoxemia? ### Response:
SELECT COUNT(DISTINCT t2.subject_id) FROM (SELECT t1.subject_id, t1.charttime 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 = 'hypoxemia')) AS t1 GROUP BY t1.subject_id HAVING MIN(t1.charttime) = t1.charttime AND STRFTIME('%y', t1.charttime) = '2101') AS t2 JOIN (SELECT patients.subject_id, admissions.hadm_id, patients.dod FROM admissions JOIN patients ON patients.subject_id = admissions.subject_id WHERE NOT patients.dod IS NULL AND STRFTIME('%y', patients.dod) = '2101') AS t3 ON t2.subject_id = t3.subject_id WHERE DATETIME(t2.charttime, 'start of month') = DATETIME(t3.dod, 'start of month')
### Instruction: how many patients were prescribed the drug glucose 15 gram/60 ml bq liq within 2 months after having been diagnosed with acute respiratory failure - due to neurological process since 2 years ago? ### 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 respiratory failure - due to neurological process' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'glucose 15 gram/60 ml bq liq' AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 WHERE t1.diagnosistime < t2.drugstarttime AND DATETIME(t2.drugstarttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month')
### Instruction: since 2 years ago, what were the five most often ordered lab tests for patients who had previously been diagnosed with s/p thoracotomy within 2 months? ### Response:
SELECT t3.labname FROM (SELECT t2.labname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 's/p thoracotomy' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, lab.labname, lab.labresulttime FROM lab JOIN patient ON lab.patientunitstayid = patient.patientunitstayid WHERE DATETIME(lab.labresulttime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.labresulttime AND DATETIME(t2.labresulttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month') GROUP BY t2.labname) AS t3 WHERE t3.c1 <= 5
### Instruction: what are the top three most frequently used specimen tests given to patients in the same hospital visit after being diagnosed with poison-medicinal agt nos? ### Response:
SELECT t3.spec_type_desc FROM (SELECT t2.spec_type_desc, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, diagnoses_icd.charttime, admissions.hadm_id 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 = 'poison-medicinal agt nos')) AS t1 JOIN (SELECT admissions.subject_id, microbiologyevents.spec_type_desc, microbiologyevents.charttime, admissions.hadm_id FROM microbiologyevents JOIN admissions ON microbiologyevents.hadm_id = admissions.hadm_id) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.charttime AND t1.hadm_id = t2.hadm_id GROUP BY t2.spec_type_desc) AS t3 WHERE t3.c1 <= 3
### Instruction: what are the five most common laboratory tests that a patient had within the same hospital visit after being diagnosed with s/p pelvic exenteration since 1 year ago? ### Response:
SELECT t3.labname FROM (SELECT t2.labname, 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 = 's/p pelvic exenteration' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-1 year')) AS t1 JOIN (SELECT patient.uniquepid, lab.labname, lab.labresulttime, patient.patienthealthsystemstayid FROM lab JOIN patient ON lab.patientunitstayid = patient.patientunitstayid WHERE DATETIME(lab.labresulttime) >= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.labresulttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.labname) AS t3 WHERE t3.c1 <= 5
### Instruction: what are the four most commonly ordered procedures in 2105 for patients who have previously been diagnosed with bone fracture(s) - clavicle in the same month? ### Response:
SELECT t3.treatmentname FROM (SELECT t2.treatmentname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'bone fracture(s) - clavicle' AND STRFTIME('%y', diagnosis.diagnosistime) = '2105') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) = '2105') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.treatmenttime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month') GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 4
### Instruction: Required: One SEDE wizard (for a possibly impossible query). https://meta.stackexchange.com/questions/305727/required-one-sede-wizard-for-a-possibly-impossible-query a query to find all questions which were closed as duplicate, matching these conditions: it must have been closed as duplicate while the score was not negative it must have been closed as duplicate while the score was below 3 it now has a negative score it is less than a year old ### Response:
SELECT p.Id AS "post_link" FROM Posts AS p INNER JOIN PostHistory AS ph ON ph.PostId = p.Id INNER JOIN Votes AS v ON v.PostId = p.Id WHERE p.Score < 0 AND NOT p.ClosedDate IS NULL AND p.CreationDate > DATEADD(d, -366, GETDATE()) AND ph.CreationDate = p.ClosedDate AND ph.PostHistoryTypeId = 10 AND Comment = 101 AND v.VoteTypeId IN (2, 3) GROUP BY p.Id HAVING NOT SUM(CASE WHEN v.VoteTypeId = 2 AND v.CreationDate <= p.ClosedDate THEN 1 WHEN v.VoteTypeId = 3 AND v.CreationDate <= p.ClosedDate THEN -1 ELSE 0 END) BETWEEN -3 AND 0
### Instruction: what are the five most frequently ordered microbiology tests for patients who received insulin earlier in the same hospital visit until 2101? ### Response:
SELECT t3.culturesite FROM (SELECT t2.culturesite, 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 = 'insulin' AND STRFTIME('%y', treatment.treatmenttime) <= '2101') AS t1 JOIN (SELECT patient.uniquepid, microlab.culturesite, microlab.culturetakentime, patient.patienthealthsystemstayid FROM microlab JOIN patient ON microlab.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', microlab.culturetakentime) <= '2101') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.culturetakentime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.culturesite) AS t3 WHERE t3.c1 <= 5
### Instruction: DUTCH 339 , is it available for me to take in Spring-Summer 2018 ? ### Response:
SELECT COUNT(*) > 0 FROM (SELECT course_id FROM student_record WHERE earn_credit = 'Y' AND student_id = 1) AS DERIVED_TABLEalias0, course AS COURSEalias0, course_offering AS COURSE_OFFERINGalias0, semester AS SEMESTERalias0 WHERE COURSEalias0.course_id = COURSE_OFFERINGalias0.course_id AND NOT COURSEalias0.course_id IN (DERIVED_TABLEalias0.course_id) AND NOT COURSEalias0.course_id IN (SELECT DISTINCT COURSE_PREREQUISITEalias0.course_id FROM course_prerequisite AS COURSE_PREREQUISITEalias0 WHERE NOT COURSE_PREREQUISITEalias0.pre_course_id IN (DERIVED_TABLEalias0.course_id)) AND COURSEalias0.department = 'DUTCH' AND COURSEalias0.number = 339 AND SEMESTERalias0.semester = 'Spring-Summer' AND SEMESTERalias0.semester_id = COURSE_OFFERINGalias0.semester AND SEMESTERalias0.year = 2018
### Instruction: what were the top four frequent diagnoses that patients were diagnosed with during the same month after having received a stress ulcer treatment - esomeprazole procedure since 2105? ### Response:
SELECT t3.diagnosisname FROM (SELECT t2.diagnosisname, 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 = 'stress ulcer treatment - esomeprazole' AND STRFTIME('%y', treatment.treatmenttime) >= '2105') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', diagnosis.diagnosistime) >= '2105') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.diagnosistime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.diagnosistime, 'start of month') GROUP BY t2.diagnosisname) AS t3 WHERE t3.c1 <= 4
### Instruction: what were the three most frequently performed procedures for patients who received c. difficile toxin previously in the same hospital encounter since 6 years ago? ### 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 = 'c. difficile toxin' AND DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-6 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-6 year')) 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 <= 3
### Instruction: since 1 year ago, what were the top five most frequent drugs prescribed to patients within 2 months after the prescription of amoxicillin oral susp.? ### Response:
SELECT t3.drug FROM (SELECT t2.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'amoxicillin oral susp.' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-1 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.drug, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.startdate < t2.startdate AND DATETIME(t2.startdate) BETWEEN DATETIME(t1.startdate) AND DATETIME(t1.startdate, '+2 month') GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 5
### Instruction: how many patients until 2104 were prescribed methylnaltrexone within 2 months after receiving a vaccination nec? ### Response:
SELECT COUNT(DISTINCT t1.subject_id) FROM (SELECT admissions.subject_id, procedures_icd.charttime 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 = 'vaccination nec') AND STRFTIME('%y', procedures_icd.charttime) <= '2104') AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'methylnaltrexone' AND STRFTIME('%y', prescriptions.startdate) <= '2104') AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND DATETIME(t2.startdate) BETWEEN DATETIME(t1.charttime) AND DATETIME(t1.charttime, '+2 month')
### Instruction: list the top five most common drugs that patients were prescribed within 2 months after being prescribed oxycodone (sustained release) since 1 year ago. ### Response:
SELECT t3.drug FROM (SELECT t2.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'oxycodone (sustained release)' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-1 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.drug, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.startdate < t2.startdate AND DATETIME(t2.startdate) BETWEEN DATETIME(t1.startdate) AND DATETIME(t1.startdate, '+2 month') GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 5
### Instruction: when was the last time patient 025-51980 got prescribed for 10 ml vial: infuvite iv inj and solu-medrol at the same time in 01/2105? ### Response:
SELECT t1.drugstarttime FROM (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = '10 ml vial: infuvite iv inj' AND patient.uniquepid = '025-51980' AND STRFTIME('%y-%m', medication.drugstarttime) = '2105-01') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'solu-medrol' AND patient.uniquepid = '025-51980' AND STRFTIME('%y-%m', medication.drugstarttime) = '2105-01') AS t2 ON t1.uniquepid = t2.uniquepid WHERE DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) ORDER BY t1.drugstarttime DESC LIMIT 1
### Instruction: what were the four most common prescription drugs for patients who had been diagnosed with septic shock previously within 2 months, since 2105? ### Response:
SELECT t3.drugname FROM (SELECT t2.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'septic shock' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2105') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', medication.drugstarttime) >= '2105') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.drugstarttime AND DATETIME(t2.drugstarttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month') GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 4
### Instruction: what are the three most common procedures that followed in the same month for patients who were given a colloid administration - hydroxyethylstarch until 2 years ago? ### 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 = 'colloid administration - hydroxyethylstarch' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month') GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 3
### Instruction: what were the top five frequently prescribed drugs that the patients were prescribed within 2 months after they had been prescribed albuterol inhaler since 4 years ago? ### Response:
SELECT t3.drug FROM (SELECT t2.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'albuterol inhaler' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-4 year')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.drug, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-4 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.startdate < t2.startdate AND DATETIME(t2.startdate) BETWEEN DATETIME(t1.startdate) AND DATETIME(t1.startdate, '+2 month') GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 5
### Instruction: Is Winter 2014 an option as a time for me to take RACKHAM 525 ? ### Response:
SELECT COUNT(*) > 0 FROM (SELECT course_id FROM student_record WHERE earn_credit = 'Y' AND student_id = 1) AS DERIVED_TABLEalias0, course AS COURSEalias0, course_offering AS COURSE_OFFERINGalias0, semester AS SEMESTERalias0 WHERE COURSEalias0.course_id = COURSE_OFFERINGalias0.course_id AND NOT COURSEalias0.course_id IN (DERIVED_TABLEalias0.course_id) AND NOT COURSEalias0.course_id IN (SELECT DISTINCT COURSE_PREREQUISITEalias0.course_id FROM course_prerequisite AS COURSE_PREREQUISITEalias0 WHERE NOT COURSE_PREREQUISITEalias0.pre_course_id IN (DERIVED_TABLEalias0.course_id)) AND COURSEalias0.department = 'RACKHAM' AND COURSEalias0.number = 525 AND SEMESTERalias0.semester = 'Winter' AND SEMESTERalias0.semester_id = COURSE_OFFERINGalias0.semester AND SEMESTERalias0.year = 2014
### Instruction: count the number of patients who received a antiarrhythmics - class iii antiarrhythmic procedure during the same month after they have been diagnosed with signs and symptoms of sepsis (sirs) a year before. ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'signs and symptoms of sepsis (sirs)' AND DATETIME(diagnosis.diagnosistime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'antiarrhythmics - class iii antiarrhythmic' AND DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t2 WHERE t1.diagnosistime < t2.treatmenttime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month')
### Instruction: since 2103 what are the top five most frequent lab tests ordered for patients during the same hospital encounter after the diagnosis of bacteremia - vascular catheter associated? ### Response:
SELECT t3.labname FROM (SELECT t2.labname, 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 = 'bacteremia - vascular catheter associated' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2103') AS t1 JOIN (SELECT patient.uniquepid, lab.labname, lab.labresulttime, patient.patienthealthsystemstayid FROM lab JOIN patient ON lab.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', lab.labresulttime) >= '2103') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.labresulttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.labname) AS t3 WHERE t3.c1 <= 5
### Instruction: Percentage of Questions by AnswerDays. ### Response:
WITH qs AS (SELECT YEAR(q.CreationDate) AS QuestionAskYear, MIN(CAST((a.CreationDate - q.CreationDate) AS FLOAT)) AS AnsweredDays FROM Posts AS q JOIN Posts AS a ON a.ParentId = q.Id AND a.PostTypeId = 2 WHERE q.PostTypeId = 1 GROUP BY q.Id, YEAR(q.CreationDate)), days AS (SELECT QuestionAskYear, CAST(AnsweredDays AS INT) - CAST(ANSWEREDdAYS AS INT) % 2 AS AnsweredDays, COUNT(*) AS Questions FROM qs GROUP BY QuestionAskYear, CAST(AnsweredDays AS INT) - CAST(ANSWEREDdAYS AS INT) % 2) SELECT AnsweredDays, '2013', '2014', '2015', '2016', '2017', '2018', '2019' FROM days PIVOT(SUM(Questions) FOR QuestionAskYear IN ('2013', '2014', '2015', '2016', '2017', '2018', '2019')) AS p WHERE AnsweredDays >= 0 AND AnsweredDays < 1000 ORDER BY AnsweredDays
### Instruction: what were the top five most frequent specimen tests that followed within the same month for patients who were diagnosed with unc behav neo meninges? ### Response:
SELECT t3.spec_type_desc FROM (SELECT t2.spec_type_desc, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 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 = 'unc behav neo meninges')) AS t1 JOIN (SELECT admissions.subject_id, microbiologyevents.spec_type_desc, microbiologyevents.charttime FROM microbiologyevents JOIN admissions ON microbiologyevents.hadm_id = admissions.hadm_id) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.charttime AND DATETIME(t1.charttime, 'start of month') = DATETIME(t2.charttime, 'start of month') GROUP BY t2.spec_type_desc) AS t3 WHERE t3.c1 <= 5
### Instruction: in 2102 what were the top four most frequent procedures that patients received in the same hospital visit after being diagnosed with hypovolemic shock? ### Response:
SELECT t3.treatmentname FROM (SELECT t2.treatmentname, 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 = 'hypovolemic shock' AND STRFTIME('%y', diagnosis.diagnosistime) = '2102') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) = '2102') AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.diagnosistime < t2.treatmenttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid GROUP BY t2.treatmentname) AS t3 WHERE t3.c1 <= 4
### Instruction: Number of questions/answers per month of question's CreationDate - with some tags excluded. ### Response:
WITH acounts_cte AS (SELECT LAST_DATE_OF_MONTH(a.CreationDate) AS Cmonth, COUNT(DISTINCT a.Id) AS Acount FROM Posts AS q INNER JOIN Posts AS a ON a.ParentId = q.Id WHERE NOT ((q.Tags LIKE '%<##tag1?big-list##>%') OR (q.Tags LIKE '%<##tag2?soft-question##>%')) GROUP BY LAST_DATE_OF_MONTH(a.CreationDate)), qcounts_cte AS (SELECT LAST_DATE_OF_MONTH(q.CreationDate) AS Cmonth, COUNT(DISTINCT q.Id) AS QCount FROM Posts AS q WHERE NOT ((q.Tags LIKE '%<##tag1>%') OR (q.Tags LIKE '%<##tag2##>%')) GROUP BY LAST_DATE_OF_MONTH(q.CreationDate)) SELECT q.Cmonth AS CMonth, CAST(q.QCount + a.ACount AS INT) AS "total_posts", q.Qcount AS "total_questions", a.Acount AS "total_answers" FROM acounts_cte AS a INNER JOIN qcounts_cte AS q ON a.Cmonth = q.Cmonth ORDER BY q.Cmonth
### Instruction: in 2104, what are the five most frequent interventions that patients were given within 2 months after receiving administration of electrolytes - magnesium? ### 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 = 'administration of electrolytes - magnesium' AND STRFTIME('%y', treatment.treatmenttime) = '2104') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', treatment.treatmenttime) = '2104') 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 <= 5