instruction
stringlengths 37
754
| output
stringlengths 9
3.43k
|
---|---|
### Instruction:
what is the number of patients who received a mechanical ventilation procedure within 2 months after having received a folate procedure this year?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'folate' AND DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'mechanical ventilation' AND DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')) AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t2.treatmenttime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month')
|
### Instruction:
is there a flight from CHARLOTTE to NEWARK on tuesday evening
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'NEWARK' AND date_day.day_number = 22 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'CHARLOTTE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.departure_time BETWEEN 1800 AND 2200
|
### Instruction:
i want a flight from HOUSTON to MEMPHIS on tuesday morning
### 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.departure_time BETWEEN 0 AND 1200) AND date_day.day_number = 22 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'MEMPHIS' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'HOUSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
Posts by a user ordered by number of links they contain.
### Response:
|
SELECT Posts.Id AS "post_link", (LENGTH(Posts.Body) - LENGTH(REPLACE(Posts.Body, 'https://' + LOWER(RIGHT(DB_NAME(DB_ID()), LENGTH(DB_NAME(DB_ID())) - STR_POSITION(DB_NAME(DB_ID()), '.'))), ''))) / 14 + (LENGTH(Posts.Body) - LENGTH(REPLACE(Posts.Body, 'http://' + LOWER(RIGHT(DB_NAME(DB_ID()), LENGTH(DB_NAME(DB_ID())) - STR_POSITION(DB_NAME(DB_ID()), '.'))), ''))) / 13 AS "Links", (CASE WHEN Posts.PostTypeId = 2 THEN 'A' ELSE 'Q' END) AS "Type", (CASE WHEN Posts.PostTypeId = 2 THEN questions.Tags ELSE Posts.Tags END) AS "Tags" FROM Posts AS posts LEFT JOIN Posts AS questions ON Posts.ParentId = questions.Id WHERE Posts.OwnerUserId = '##UserId##' ORDER BY Links DESC
|
### Instruction:
what flights from SAN JOSE to DALLAS on friday afternoon
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DALLAS' AND date_day.day_number = 25 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SAN JOSE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.departure_time BETWEEN 1200 AND 1800
|
### Instruction:
what are the four most frequently prescribed drugs for patients that have been prescribed clopidogrel bisulfate at the same time, since 2105?
### 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 = 'clopidogrel bisulfate' AND STRFTIME('%y', prescriptions.startdate) >= '2105') AS t1 JOIN (SELECT admissions.subject_id, prescriptions.drug, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE STRFTIME('%y', prescriptions.startdate) >= '2105') AS t2 ON t1.subject_id = t2.subject_id WHERE DATETIME(t1.startdate) = DATETIME(t2.startdate) GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 4
|
### Instruction:
i would like flights between BOSTON and ATLANTA on 7 11 departing at one in the afternoon
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((date_day.day_number = 11 AND date_day.month_number = 7 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.departure_time = 1300 AND flight.flight_days = days.days_code) 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 = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
what flights are available from ATLANTA to OAKLAND with one way economy fares
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, fare_basis, flight, flight_fare WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'OAKLAND' AND fare_basis.economy = 'YES' AND fare.fare_basis_code = fare_basis.fare_basis_code AND fare.round_trip_required = 'NO' AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'ATLANTA' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
what were the changes in the sao2 of patient 021-111547 last measured on the current intensive care unit visit compared to the first value measured on the current intensive care unit visit?
### Response:
|
SELECT (SELECT vitalperiodic.sao2 FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-111547') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.sao2 IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1) - (SELECT vitalperiodic.sao2 FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-111547') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.sao2 IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1)
|
### Instruction:
what 's the cost of a FIRST class fare from PHILADELPHIA to SAN FRANCISCO
### Response:
|
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, fare_basis, flight, flight_fare WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PHILADELPHIA' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND fare_basis.class_type = 'FIRST' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
|
### Instruction:
what is the change in the bun of patient 009-10951 last measured on the last hospital visit compared to the first value measured on the last hospital visit.
### Response:
|
SELECT (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '009-10951' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND lab.labname = 'bun' ORDER BY lab.labresulttime DESC LIMIT 1) - (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '009-10951' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND lab.labname = 'bun' ORDER BY lab.labresulttime LIMIT 1)
|
### Instruction:
how many patients since 2 years ago were prescribed heparin (porcine) within 2 months after the pulmonary/ccm consultation?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'pulmonary/ccm consultation' AND DATETIME(treatment.treatmenttime) >= 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 = 'heparin (porcine)' AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 WHERE t1.treatmenttime < t2.drugstarttime AND DATETIME(t2.drugstarttime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month')
|
### Instruction:
Follow-up edits to my contributions. Shows all posts that I've contributed to, that have also been edited by someone else since my last contribution. Includes only certain types of edits (title/body/tag edits/rollbacks), and excludes edits by the Community user (which are mostly inserting/removing duplicate links and such).
### Response:
|
SELECT ph.PostId AS "post_link", ph.CreationDate AS LastEditDate, u.DisplayName AS LastEditor, pht.Name AS LastEditType, ph.Comment FROM PostHistory AS ph JOIN PostHistoryTypes AS pht ON pht.Id = ph.PostHistoryTypeId JOIN Posts AS p ON p.Id = ph.PostId AND p.LastEditDate = ph.CreationDate JOIN Users AS u ON u.Id = ph.UserId AND u.Id = p.LastEditorUserId WHERE ph.UserId != -1 AND ph.UserId != '##UserId##' AND ph.PostHistoryTypeId IN (4, 5, 6, 7, 8, 9) AND EXISTS(SELECT 1 FROM PostHistory WHERE PostId = ph.PostId AND UserId = '##UserId##' AND CreationDate < ph.CreationDate) ORDER BY ph.CreationDate
|
### Instruction:
how many patients were prescribed with docusate sodium 100 mg cap during the same hospital visit in 2103 after the diagnosis with hypertension?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'hypertension' AND STRFTIME('%y', diagnosis.diagnosistime) = '2103') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'docusate sodium 100 mg cap' AND STRFTIME('%y', medication.drugstarttime) = '2103') AS t2 WHERE t1.diagnosistime < t2.drugstarttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
|
### Instruction:
how many patients were until 2102 diagnosed with bone fracture(s) - sternum within 2 months after having undergone neuroradiology consultation?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'neuroradiology consultation' AND STRFTIME('%y', treatment.treatmenttime) <= '2102') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'bone fracture(s) - sternum' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2102') AS t2 WHERE t1.treatmenttime < t2.diagnosistime AND DATETIME(t2.diagnosistime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month')
|
### Instruction:
what is the name of drug patient 88659 was prescribed in the same hospital encounter after receiving a endosc destruc bronc les procedure?
### Response:
|
SELECT t2.drug 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 admissions.subject_id = 88659 AND procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'endosc destruc bronc les')) 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.subject_id = 88659) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND t1.hadm_id = t2.hadm_id
|
### Instruction:
count the number of patients who were diagnosed with dka during the same hospital encounter since 2100 after receiving a antidepressant - vanafaxine (effexor) procedure.
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'antidepressant - vanafaxine (effexor)' AND STRFTIME('%y', treatment.treatmenttime) >= '2100') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'dka' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2100') AS t2 WHERE t1.treatmenttime < t2.diagnosistime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
|
### Instruction:
among the patients who were diagnosed with bone fracture(s) - right lower extremity tell me the three year survival rate.
### Response:
|
SELECT SUM(CASE WHEN patient.hospitaldischargestatus = 'alive' THEN 1 WHEN STRFTIME('%j', patient.hospitaldischargetime) - STRFTIME('%j', t2.diagnosistime) > 3 * 365 THEN 1 ELSE 0 END) * 100 / COUNT(*) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'bone fracture(s) - right lower extremity' GROUP BY patient.uniquepid HAVING MIN(diagnosis.diagnosistime) = diagnosis.diagnosistime) AS t1 WHERE STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', t1.diagnosistime) > 3 * 365) AS t2 JOIN patient ON t2.uniquepid = patient.uniquepid
|
### Instruction:
tell me about flights on AA from DALLAS to SAN FRANCISCO on 6 29
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND date_day.day_number = 29 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DALLAS' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'AA'
|
### Instruction:
The distribution of scores on questions, by answer count. The distribution of scores on questions, by answer count
### Response:
|
SELECT AnswerCount AS "answers", COUNT(*) AS "#questions", ROUND(100.0 * COUNT(CASE WHEN Score < 0 THEN 1 END) / COUNT(*), 2) AS "%_score<0", ROUND(100.0 * COUNT(CASE WHEN Score = 0 THEN 1 END) / COUNT(*), 1) AS "%_score=0", ROUND(100.0 * COUNT(CASE WHEN Score = 1 THEN 1 END) / COUNT(*), 1) AS "%_score=1", ROUND(100.0 * COUNT(CASE WHEN Score = 2 THEN 1 END) / COUNT(*), 1) AS "%_score=2", ROUND(100.0 * COUNT(CASE WHEN Score = 3 THEN 1 END) / COUNT(*), 1) AS "%_score=3", ROUND(100.0 * COUNT(CASE WHEN Score > 3 THEN 1 END) / COUNT(*), 1) AS "%_score>3" FROM Posts WHERE PostTypeId = 1 AND AnswerCount >= 0 GROUP BY AnswerCount ORDER BY AnswerCount
|
### Instruction:
how much does patient 035-24054 change in systemicmean second measured on the current intensive care unit visit compared to the first value measured on the current intensive care unit visit?
### Response:
|
SELECT (SELECT vitalperiodic.systemicmean FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '035-24054') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.systemicmean IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1 OFFSET 1) - (SELECT vitalperiodic.systemicmean FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '035-24054') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.systemicmean IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1)
|
### Instruction:
what 's the FIRST class fare round trip from ATLANTA to DENVER
### Response:
|
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, fare_basis, flight, flight_fare WHERE (CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'ATLANTA' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DENVER' AND NOT fare.round_trip_cost IS NULL AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND fare_basis.class_type = 'FIRST' AND fare.fare_basis_code = fare_basis.fare_basis_code
|
### Instruction:
what are the five most commonly prescribed medications for patients that are also prescribed with nss infusion at the same time, in 2105?
### 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 = 'nss infusion' AND STRFTIME('%y', medication.drugstarttime) = '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 DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 5
|
### Instruction:
what are the four most commonly prescribed medications for patients that are also prescribed with propofol at the same time, until 2 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 = 'propofol' AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-2 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(), '-2 year')) AS t2 ON t1.subject_id = t2.subject_id WHERE DATETIME(t1.startdate) = DATETIME(t2.startdate) GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 4
|
### Instruction:
when for the first time until 31 months ago was patient 26922 prescribed d5w and furosemide at the same time?
### 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 = 'd5w' AND admissions.subject_id = 26922 AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-31 month')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'furosemide' AND admissions.subject_id = 26922 AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-31 month')) AS t2 ON t1.subject_id = t2.subject_id WHERE DATETIME(t1.startdate) = DATETIME(t2.startdate) ORDER BY t1.startdate LIMIT 1
|
### Instruction:
among patients who were prescribed with roxicodone, what are the three most frequently prescribed drugs at the same time, in 2100?
### 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 = 'roxicodone' AND STRFTIME('%y', medication.drugstarttime) = '2100') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', medication.drugstarttime) = '2100') AS t2 ON t1.uniquepid = t2.uniquepid WHERE DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 3
|
### Instruction:
list flights leaving DENVER and arriving in ORLANDO on saturday departing after 12pm
### 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 ((date_day.day_number = 26 AND date_day.month_number = 7 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.departure_time > 1200 AND flight.flight_days = days.days_code) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ORLANDO' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DENVER' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
what are the name of the drug that patient 52647 was prescribed in the same hospital visit after receiving a sm bowel stoma closure?
### Response:
|
SELECT t2.drug 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 admissions.subject_id = 52647 AND procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'sm bowel stoma closure')) 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.subject_id = 52647) AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND t1.hadm_id = t2.hadm_id
|
### Instruction:
i want to go from BOSTON to WASHINGTON on monday morning
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'WASHINGTON' AND date_day.day_number = 21 AND date_day.month_number = 2 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.departure_time BETWEEN 0 AND 1200
|
### Instruction:
How to calculate statistics on stackoverflow?. http://meta.stackoverflow.com/questions/297236/how-to-calculate-statistics-on-stackoverflow/313188#313188
### Response:
|
SELECT YEAR(v.CreationDate), COUNT(*) AS total, SUM(CASE WHEN v.VoteTypeId = 2 THEN 1 ELSE 0 END) AS upvotes, SUM(CASE WHEN v.VoteTypeId = 3 THEN 1 ELSE 0 END) AS downvotes, SUM(CASE WHEN v.VoteTypeId = 2 AND t.TagName = 'c#' THEN 1 ELSE 0 END) AS "c#_up_votes", SUM(CASE WHEN v.VoteTypeId = 3 AND t.TagName = 'c#' THEN 1 ELSE 0 END) AS "c#_down_votes" FROM Votes AS v INNER JOIN PostTags AS pt ON v.PostId = pt.PostId INNER JOIN Tags AS t ON t.Id = pt.TagId WHERE t.TagName IN ('c#', 'java', 'c++', 'php', 'javascript') AND v.VoteTypeId IN (2, 3) GROUP BY YEAR(v.CreationDate)
|
### Instruction:
show flights leaving BOSTON on wednesday morning and arriving in DENVER
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DENVER' AND date_day.day_number = 23 AND date_day.month_number = 4 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.departure_time BETWEEN 0 AND 1200
|
### Instruction:
what number of patients were prescribed thiamine study drug (*ind*) in the same hospital visit after having been diagnosed with ath ext ntv art gngrene?
### 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 = 'ath ext ntv art gngrene')) 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 = 'thiamine study drug (*ind*)') AS t2 ON t1.subject_id = t2.subject_id WHERE t1.charttime < t2.startdate AND t1.hadm_id = t2.hadm_id
|
### Instruction:
how many patients died after having been diagnosed with hemorrhage within the same hospital visit until 1 year ago?
### Response:
|
SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT t1.uniquepid, t1.diagnosistime, t1.patienthealthsystemstayid FROM (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'hemorrhage') AS t1 GROUP BY t1.uniquepid HAVING MIN(t1.diagnosistime) = t1.diagnosistime AND DATETIME(t1.diagnosistime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 JOIN (SELECT patient.uniquepid, patient.patienthealthsystemstayid, patient.hospitaldischargetime FROM patient WHERE patient.hospitaldischargestatus = 'expired') AS t3 ON t2.uniquepid = t3.uniquepid WHERE t2.patienthealthsystemstayid = t3.patienthealthsystemstayid
|
### Instruction:
what are the three most common procedures given to patients who are diagnosed with cardiac arrest - initial rhythm: ventricular fibrillation previously during 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 = 'cardiac arrest - initial rhythm: ventricular fibrillation') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmentname, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid) AS t2 ON t1.uniquepid = t2.uniquepid WHERE t1.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 <= 3
|
### Instruction:
Difference in score by delay between answers, if more than 30 days.
### Response:
|
WITH two_answers AS (SELECT MIN(a.Id) AS first, MAX(a.Id) AS last FROM Posts AS q JOIN Posts AS a ON q.Id = a.ParentId WHERE q.AnswerCount = 2 GROUP BY q.Id HAVING GETDATE() - MAX(a.CreationDate) > 30) SELECT MIN(DATEDIFF(hour, f.CreationDate, CreationDate)), AVG(CAST(ISNULL(f.Score, 0) AS FLOAT) - CAST(ISNULL(l.Score, 0) AS FLOAT)) AS delta FROM two_answers JOIN Posts AS f ON f.Id = first JOIN Posts AS l ON l.Id = last WHERE ISNULL(f.Score, 0) >= 0 AND ISNULL(l.Score, 0) >= 0 AND f.CreationDate < l.CreationDate AND DATEDIFF(month, f.CreationDate, CreationDate) < 1 GROUP BY DATEDIFF(hour, f.CreationDate, CreationDate) ORDER BY DATEDIFF(hour, f.CreationDate, CreationDate)
|
### Instruction:
what flights leave BALTIMORE for BOSTON after 600 o'clock on friday
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((date_day.day_number = 25 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.departure_time > 600 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 = 'BALTIMORE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
how many patients were diagnosed with av block - complete heart block during the same hospital encounter until 2104 after having been previously diagnosed with congestive heart failure?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'av block - complete heart block' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2104') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'congestive heart failure' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2104') AS t2 WHERE t1.diagnosistime < t2.diagnosistime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
|
### Instruction:
Questions per month, Config Mgmt Frameworks. How do Scala web frameworks compare to each other?
I'm restricting the questions to those tagged Scala, to avoid polluting Playframework's result. It might be unfair, but I can't think of any other way to do it. At least all frameworks are being equally discriminated against.
### Response:
|
SELECT *, COUNT(*) FROM (SELECT DATE(CAST(TIME_TO_STR(CreationDate, '%Y') AS TEXT) + '-' + CAST(TIME_TO_STR(CreationDate, '%m') AS TEXT) + '-01') AS Month, t.TagName FROM (SELECT p.Id, p.CreationDate FROM Posts AS p JOIN PostTags AS pt ON pt.PostId = p.Id JOIN Tags AS t ON t.Id = pt.TagId) AS pp JOIN PostTags AS pt ON pt.PostId = pp.Id JOIN Tags AS t ON t.Id = pt.TagId WHERE t.TagName IN ('ansible-ssh', 'ansible', 'ansible-playbook', 'puppet', 'cfengine', 'chef', 'chef-recipe', 'salt-stack')) AS X GROUP BY TagName, Month ORDER BY Month, COUNT(*) DESC
|
### Instruction:
i need a flight from BALTIMORE to DALLAS tomorrow morning
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DALLAS' AND date_day.day_number = 20 AND date_day.month_number = 1 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BALTIMORE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.departure_time BETWEEN 0 AND 1200
|
### Instruction:
is the respiration value of patient 027-136480 last measured on the current intensive care unit visit less than second to last measured on the current intensive care unit visit?
### Response:
|
SELECT (SELECT vitalperiodic.respiration FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '027-136480') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.respiration IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1) < (SELECT vitalperiodic.respiration FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '027-136480') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.respiration IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1 OFFSET 1)
|
### Instruction:
is the value of patient 016-9636's last sao2 measured on the current icu visit greater than the second to last value measured on the current icu visit?
### Response:
|
SELECT (SELECT vitalperiodic.sao2 FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '016-9636') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.sao2 IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1) > (SELECT vitalperiodic.sao2 FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '016-9636') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.sao2 IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1 OFFSET 1)
|
### Instruction:
how many flights are there between SAN FRANCISCO and PHILADELPHIA on 8 18
### Response:
|
SELECT COUNT(DISTINCT flight.flight_id) FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHILADELPHIA' AND date_day.day_number = 18 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SAN FRANCISCO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
is it patient 002-64535's hct second measured on the first hospital visit less than first measured on the first hospital visit?
### Response:
|
SELECT (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '002-64535' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND lab.labname = 'hct' ORDER BY lab.labresulttime LIMIT 1 OFFSET 1) < (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '002-64535' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND lab.labname = 'hct' ORDER BY lab.labresulttime LIMIT 1)
|
### Instruction:
did the value of mcv of patient 002-41152 last measured on the last hospital visit be greater than first measured on the last hospital visit?
### Response:
|
SELECT (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '002-41152' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND lab.labname = 'mcv' ORDER BY lab.labresulttime DESC LIMIT 1) > (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '002-41152' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND lab.labname = 'mcv' ORDER BY lab.labresulttime LIMIT 1)
|
### Instruction:
R versus Python tags - quotient Py/R.
### Response:
|
SELECT DATE(CAST(t.yr AS TEXT(4)) + '-' + CAST(t.mnth AS TEXT(2)) + '-01') AS dt, (CASE WHEN t.r_mnth_count = 0 THEN NULL ELSE CAST(t.py_mnth_count AS FLOAT) / CAST(t.r_mnth_count AS FLOAT) END) AS py_div_r FROM (SELECT MONTH(CreationDate) AS mnth, YEAR(CreationDate) AS yr, SUM(CASE WHEN Tags LIKE '%<r>%' THEN 1 ELSE 0 END) AS r_mnth_count, SUM(CASE WHEN Tags LIKE '%<python>%' THEN 1 ELSE 0 END) AS py_mnth_count FROM Posts WHERE Tags LIKE '%<r>%' OR Tags LIKE '%<python>%' GROUP BY MONTH(CreationDate), YEAR(CreationDate)) AS t WHERE NOT (t.mnth = MONTH(CURRENT_TIMESTAMP()) AND t.yr = YEAR(CURRENT_TIMESTAMP())) AND yr >= 2014 ORDER BY t.yr, t.mnth
|
### Instruction:
show me a list of flights on AA from BOSTON to WASHINGTON on 7 22
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'WASHINGTON' AND date_day.day_number = 22 AND date_day.month_number = 7 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'AA'
|
### Instruction:
Questions with a specific tag both at first and current revision.
### Response:
|
SELECT SUM(CASE WHEN HadTag = 1 AND HasTag = 0 THEN 1 ELSE 0 END) AS TagRemoved, SUM(CASE WHEN HadTag = 0 AND HasTag = 1 THEN 1 ELSE 0 END) AS TagAdded, SUM(CASE WHEN HadTag = 1 AND HasTag = 1 THEN 1 ELSE 0 END) AS TagPersisted, SUM(CASE WHEN HadTag = 1 OR HasTag = 1 THEN 1 ELSE 0 END) AS Total FROM (SELECT CASE WHEN Posts.Tags LIKE '%##Tag##%' THEN 1 ELSE 0 END AS HasTag, HadTag FROM Posts INNER JOIN (SELECT PostId, Text, CASE WHEN Text LIKE '%##Tag##%' THEN 1 ELSE 0 END AS HadTag FROM PostHistory WHERE PostHistoryTypeId = 3) AS PostInits ON Posts.Id = PostInits.PostId WHERE (DATEDIFF(month, Posts.CreationDate, GETDATE()) <= '##MaxQuestionAgeInMonths:int?24##') AND (DATEDIFF(month, Posts.CreationDate, GETDATE()) >= '##MinQuestionAgeInMonths:int?0##')) AS sq
|
### Instruction:
what is the variation of patient 016-18575's respiration second measured on the current intensive care unit visit compared to the first value measured on the current intensive care unit visit?
### Response:
|
SELECT (SELECT vitalperiodic.respiration FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '016-18575') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.respiration IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1 OFFSET 1) - (SELECT vitalperiodic.respiration FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '016-18575') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.respiration IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1)
|
### Instruction:
how many patients died within the same month after being diagnosed last year with hypothyroidism?
### Response:
|
SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'hypothyroidism') AS t1 GROUP BY t1.uniquepid HAVING MIN(t1.diagnosistime) = t1.diagnosistime AND DATETIME(t1.diagnosistime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')) AS t2 JOIN (SELECT patient.uniquepid, patient.patienthealthsystemstayid, patient.hospitaldischargetime FROM patient WHERE patient.hospitaldischargestatus = 'expired') AS t3 ON t2.uniquepid = t3.uniquepid WHERE DATETIME(t2.diagnosistime, 'start of month') = DATETIME(t3.hospitaldischargetime, 'start of month')
|
### Instruction:
give me the AA flights from PHOENIX to MILWAUKEE on wednesday
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'MILWAUKEE' AND date_day.day_number = 23 AND date_day.month_number = 4 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PHOENIX' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'AA'
|
### Instruction:
Questions and Answers Score Distribution.
### Response:
|
SELECT PostTypeId, Score, COUNT(Id) FROM (SELECT CASE WHEN Score < 0 THEN '0- < 0' WHEN Score BETWEEN 0 AND 100 THEN '1- 0-100' WHEN Score BETWEEN 101 AND 500 THEN '2- 101-500' WHEN Score BETWEEN 501 AND 1000 THEN '3- 501-1000' WHEN Score BETWEEN 1001 AND 2000 THEN '4- 1001-2000' WHEN Score BETWEEN 2001 AND 5000 THEN '5- 2001-5000' WHEN Score BETWEEN 5001 AND 10000 THEN '6- 5001-10000' ELSE '7- 10000+' END AS "Score", Id, PostTypeId FROM Posts WHERE PostTypeId IN (1, 2)) AS t GROUP BY PostTypeId, Score ORDER BY PostTypeId, Score
|
### Instruction:
from NEW YORK to TORONTO on thursday morning
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'TORONTO' AND date_day.day_number = 24 AND date_day.month_number = 5 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'NEW YORK' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.departure_time BETWEEN 0 AND 1200
|
### Instruction:
what is the three most frequently prescribed drugs for patients that have been prescribed with glucagon at the same time in 2102?
### 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 = 'glucagon' AND STRFTIME('%y', medication.drugstarttime) = '2102') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE STRFTIME('%y', medication.drugstarttime) = '2102') AS t2 ON t1.uniquepid = t2.uniquepid WHERE DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) GROUP BY t2.drugname) AS t3 WHERE t3.c1 <= 3
|
### Instruction:
calculate the number of patients who were dead after being diagnosed with coagulopathy within the same month until 1 year ago.
### Response:
|
SELECT COUNT(DISTINCT t2.uniquepid) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'coagulopathy') AS t1 GROUP BY t1.uniquepid HAVING MIN(t1.diagnosistime) = t1.diagnosistime AND DATETIME(t1.diagnosistime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 JOIN (SELECT patient.uniquepid, patient.patienthealthsystemstayid, patient.hospitaldischargetime FROM patient WHERE patient.hospitaldischargestatus = 'expired') AS t3 ON t2.uniquepid = t3.uniquepid WHERE DATETIME(t2.diagnosistime, 'start of month') = DATETIME(t3.hospitaldischargetime, 'start of month')
|
### Instruction:
what are the UA flights between BALTIMORE and DENVER on 8 12
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DENVER' AND date_day.day_number = 12 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BALTIMORE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'UA'
|
### Instruction:
among patients who have been diagnosed with upper respiratory obstruction - due to tumor tell me the four year survival rate.
### Response:
|
SELECT SUM(CASE WHEN patient.hospitaldischargestatus = 'alive' THEN 1 WHEN STRFTIME('%j', patient.hospitaldischargetime) - STRFTIME('%j', t2.diagnosistime) > 4 * 365 THEN 1 ELSE 0 END) * 100 / COUNT(*) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'upper respiratory obstruction - due to tumor' GROUP BY patient.uniquepid HAVING MIN(diagnosis.diagnosistime) = diagnosis.diagnosistime) AS t1 WHERE STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', t1.diagnosistime) > 4 * 365) AS t2 JOIN patient ON t2.uniquepid = patient.uniquepid
|
### Instruction:
show me flights from BOSTON to DENVER early am on tuesday
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DENVER' AND date_day.day_number = 22 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.departure_time BETWEEN 0 AND 800
|
### Instruction:
Count of users with a well-received question or answer by month. Well-received means: 1) not closed (for questions) 2) not deleted 3) positive score after 30 days
### Response:
|
WITH Raw AS (SELECT Posts.Id, MIN(Posts.OwnerUserId) AS UserId, MIN(DATEFROMPARTS(DATEPART(yyyy, Posts.CreationDate), DATEPART(mm, Posts.CreationDate), 1)) AS Month, MIN(Posts.PostTypeId) AS PostTypeId, SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE -1 END) AS Score FROM Posts, Votes WHERE Posts.PostTypeId BETWEEN 1 AND 2 AND Votes.PostId = Posts.Id AND Posts.OwnerUserId > 0 AND DATEDIFF(Day, Posts.CreationDate, CreationDate) BETWEEN 0 AND 30 GROUP BY Posts.Id) SELECT Month, CASE WHEN PostTypeId = 1 THEN 'Question' ELSE 'Answer' END AS PostType, COUNT(DISTINCT UserId) AS Count FROM Raw WHERE Score > 0 GROUP BY Month, PostTypeId ORDER BY Month DESC, PostType
|
### Instruction:
compared to last measured on the first hospital visit patient 015-57922's hct is less than the value first measured on the first hospital visit?
### Response:
|
SELECT (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '015-57922' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND lab.labname = 'hct' ORDER BY lab.labresulttime DESC LIMIT 1) < (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '015-57922' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND lab.labname = 'hct' ORDER BY lab.labresulttime LIMIT 1)
|
### Instruction:
i'd like information on all the flights from SAN FRANCISCO to PITTSBURGH on tuesday
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PITTSBURGH' AND date_day.day_number = 22 AND date_day.month_number = 3 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SAN FRANCISCO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
count the number of patients who have received a glucocorticoid administration - inhaled procedure within the same month after receiving a c. difficile toxin treatment until 2 years ago.
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'c. difficile toxin' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'glucocorticoid administration - inhaled' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month')
|
### Instruction:
Number of tag-removals (per user).
### Response:
|
WITH revisions_cte AS (SELECT DISTINCT p.Id AS pid, ph1.Id AS phId FROM PostHistory AS ph1 INNER JOIN Posts AS p ON ph1.PostId = p.Id WHERE ph1.PostHistoryTypeId IN (3, 6, 9) AND ph1.Text LIKE '%<##tagName##>%' AND NOT (p.Tags LIKE '%<##tagName##>%')), firstrev_cte AS (SELECT pid, MIN(ph2.Id) AS MinId FROM revisions_cte INNER JOIN PostHistory AS ph2 ON ph2.PostId = pid WHERE (ph2.Id > phId) AND ph2.PostHistoryTypeId IN (3, 6, 9) AND NOT (ph2.Text LIKE '%<##tagName##>%') GROUP BY pid), users_cte AS (SELECT PostId AS pid, UserId AS uid, UserDisplayName AS udn FROM PostHistory INNER JOIN firstrev_cte ON PostHistory.Id = MinId) SELECT COUNT(pid) AS Count, uid AS "user_link", udn FROM users_cte GROUP BY uid, udn ORDER BY COUNT(pid) DESC
|
### Instruction:
what is the change in the amount of wbc x 1000 in patient 017-45919 second measured on the current hospital visit compared to the first value measured on the current hospital visit?
### Response:
|
SELECT (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '017-45919' AND patient.hospitaldischargetime IS NULL)) AND lab.labname = 'wbc x 1000' ORDER BY lab.labresulttime LIMIT 1 OFFSET 1) - (SELECT lab.labresult FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '017-45919' AND patient.hospitaldischargetime IS NULL)) AND lab.labname = 'wbc x 1000' ORDER BY lab.labresulttime LIMIT 1)
|
### Instruction:
Fast-gun' distribution for a user.
### Response:
|
WITH Dates AS (SELECT a.Id, q.CreationDate AS QDate, a.CreationDate AS ADate FROM Posts AS q, Posts AS a WHERE q.Id = a.ParentId AND q.PostTypeId = 1 AND a.PostTypeId = 2 AND a.OwnerUserId = '##UserId##'), Delays AS (SELECT Id, CAST((JULIANDAY(ADate) - JULIANDAY(QDate)) * 1440.0 AS INT) AS Delay FROM Dates) SELECT SUM(CASE WHEN Delay <= 15 THEN 1 ELSE 0 END) AS WITHin15, SUM(CASE WHEN Delay > 15 AND Delay <= 30 THEN 1 ELSE 0 END) AS WITHin30, SUM(CASE WHEN Delay > 30 AND Delay <= 45 THEN 1 ELSE 0 END) AS WITHin45, SUM(CASE WHEN Delay > 45 AND Delay <= 60 THEN 1 ELSE 0 END) AS WITHinHour, SUM(CASE WHEN Delay > 60 THEN 1 ELSE 0 END) AS MoreThanHour FROM Delays
|
### Instruction:
i would like the time of all flights from SAN FRANCISCO to PITTSBURGH on sunday
### Response:
|
SELECT DISTINCT flight.departure_time FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PITTSBURGH' AND date_day.day_number = 27 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SAN FRANCISCO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
are the values of bilirubin, total of patient 13841 second measured on the last hospital visit greater than those first measured on the last hospital visit?
### Response:
|
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 13841 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'bilirubin, total') ORDER BY labevents.charttime LIMIT 1 OFFSET 1) > (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 13841 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'bilirubin, total') ORDER BY labevents.charttime LIMIT 1)
|
### Instruction:
is BREAKFAST served on flight UA 343 from BOSTON to DENVER coach class
### Response:
|
SELECT DISTINCT food_service.compartment, food_service.meal_code, food_service.meal_number FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight, food_service WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DENVER' AND flight.flight_number = 343 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 flight.airline_code = 'UA' AND food_service.meal_code = flight.meal_code AND food_service.meal_description = 'BREAKFAST'
|
### Instruction:
how many patients in 2105 were diagnosed with hypercalcemia - moderate during the same hospital visit after enteral feeds - tube feeding procedures?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'enteral feeds - tube feeding' AND STRFTIME('%y', treatment.treatmenttime) = '2105') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'hypercalcemia - moderate' AND STRFTIME('%y', diagnosis.diagnosistime) = '2105') AS t2 WHERE t1.treatmenttime < t2.diagnosistime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
|
### Instruction:
what is the one year survival rate of a person with hypomagnesemia - due to etoh abuse?
### Response:
|
SELECT SUM(CASE WHEN patient.hospitaldischargestatus = 'alive' THEN 1 WHEN STRFTIME('%j', patient.hospitaldischargetime) - STRFTIME('%j', t2.diagnosistime) > 1 * 365 THEN 1 ELSE 0 END) * 100 / COUNT(*) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'hypomagnesemia - due to etoh abuse' GROUP BY patient.uniquepid HAVING MIN(diagnosis.diagnosistime) = diagnosis.diagnosistime) AS t1 WHERE STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', t1.diagnosistime) > 1 * 365) AS t2 JOIN patient ON t2.uniquepid = patient.uniquepid
|
### Instruction:
in 2105, how many patients underwent therapeutic antibacterials - penicillins during the same hospital encounter after the previous mri - spine?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'mri - spine' AND STRFTIME('%y', treatment.treatmenttime) = '2105') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'therapeutic antibacterials - penicillins' AND STRFTIME('%y', treatment.treatmenttime) = '2105') AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
|
### Instruction:
count the number of patients who were prescribed pantoprazole sodium within the same month after receiving a cont inv mec ven 96+ hrs procedure.
### 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 = 'cont inv mec ven 96+ hrs')) AS t1 JOIN (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'pantoprazole sodium') 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:
Top editors with type breakdown. Does not count edits to one's own posts.
Does not count rollbacks.
Does not count edits to community wiki posts after they were made CW.
### Response:
|
SELECT h.UserId AS "user_link", SUM(CASE WHEN PostHistoryTypeId = 6 THEN 1 ELSE 0 END) AS "retags", SUM(CASE WHEN PostHistoryTypeId = 5 THEN 1 ELSE 0 END) AS "body_edits", SUM(CASE WHEN PostHistoryTypeId = 4 THEN 1 ELSE 0 END) AS "title_edits", COUNT(DISTINCT h.CreationDate) AS "total_edits", COUNT(DISTINCT h.PostId) AS "total_edited_posts" FROM PostHistory AS h, Posts AS p WHERE p.Id = h.PostId AND (h.PostHistoryTypeId = 4 OR h.PostHistoryTypeId = 5 OR h.PostHistoryTypeId = 6) AND h.UserId != p.OwnerUserId AND (p.CommunityOwnedDate IS NULL OR h.CreationDate < p.CommunityOwnedDate) GROUP BY h.UserId ORDER BY 'total_edited_posts' DESC
|
### Instruction:
Score of first question/answer after N days by user.
### Response:
|
SELECT fp.OwnerUserId AS "user_link", p1.Id AS "post_link", SUM(CASE WHEN v.VoteTypeId = 2 THEN 1 WHEN v.VoteTypeId = 3 THEN -1 ELSE 0 END) AS ScoreThen FROM (SELECT p.OwnerUserId, MIN(p.CreationDate) AS dateFirstPost FROM Posts AS p WHERE p.PostTypeId = '##Choose1forQ2forA##' GROUP BY p.OwnerUserId) AS fp INNER JOIN Posts AS p1 ON p1.CreationDate = fp.dateFirstPost AND p1.OwnerUserId = fp.OwnerUserId INNER JOIN Votes AS v ON v.PostId = p1.Id AND DATEDIFF(d, p1.CreationDate, creationdate) <= '##N##' AND (v.VoteTypeId = 2 OR v.VoteTypeId = 3) GROUP BY fp.OwnerUserId, p1.Id ORDER BY SUM(CASE WHEN v.VoteTypeId = 2 THEN 1 WHEN v.VoteTypeId = 3 THEN -1 ELSE 0 END) DESC
|
### Instruction:
airlines that fly to MIAMI from NEW YORK on friday
### Response:
|
SELECT DISTINCT airline.airline_code 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 (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'MIAMI' AND date_day.day_number = 25 AND date_day.month_number = 6 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'NEW YORK' AND flight.airline_code = airline.airline_code AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
list all AA flight from MILWAUKEE to PHOENIX on sunday
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHOENIX' AND date_day.day_number = 27 AND date_day.month_number = 8 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'MILWAUKEE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'AA'
|
### Instruction:
how many patients were prescribed magnesium sulfate 50 % ij soln in the same month after the diagnosis of anxiety, since 2104?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'anxiety' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2104') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'magnesium sulfate 50 % ij soln' AND STRFTIME('%y', medication.drugstarttime) >= '2104') AS t2 WHERE t1.diagnosistime < t2.drugstarttime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.drugstarttime, 'start of month')
|
### Instruction:
Is there a way to see the what percentage you are in a particular tag?. http://meta.stackexchange.com/questions/283693/is-there-a-way-to-see-the-what-percentage-you-are-in-a-particular-tag
### Response:
|
WITH tagleague AS (SELECT p.OwnerUserId, SUM(Score) AS score, COUNT(*) AS posts, RANK() OVER (ORDER BY SUM(Score) DESC) AS tagrank FROM Posts AS p INNER JOIN PostTags AS pt ON pt.PostId = COALESCE(p.ParentId, p.Id) INNER JOIN Tags AS t ON t.Id = pt.TagId WHERE t.TagName = '##tagname:string?java##' AND NOT p.OwnerUserId IS NULL AND PostTypeId IN (1, 2) GROUP BY OwnerUserId) SELECT OwnerUserId AS "user_link", (CAST(tagrank AS FLOAT) / (SELECT COUNT(*) FROM tagleague) * 100) AS perc, (SELECT COUNT(*) FROM tagleague) AS total, tagrank FROM tagleague WHERE OwnerUserId = '##userid:int?1475228##'
|
### Instruction:
how much of a change in patient 18517's hematocrit is taking place second measured on the first hospital visit compared to the first value measured on the first hospital visit?
### Response:
|
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 18517 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'hematocrit') ORDER BY labevents.charttime LIMIT 1 OFFSET 1) - (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 18517 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'hematocrit') ORDER BY labevents.charttime LIMIT 1)
|
### Instruction:
give me the difference between the total input and the output of patient 021-100763 on the last icu visit.
### Response:
|
SELECT (SELECT SUM(intakeoutput.cellvaluenumeric) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-100763') AND NOT patient.unitdischargetime IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1) AND intakeoutput.cellpath LIKE '%intake%') - (SELECT SUM(intakeoutput.cellvaluenumeric) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-100763') AND NOT patient.unitdischargetime IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1) AND intakeoutput.cellpath LIKE '%output%')
|
### Instruction:
what are the four most frequent drugs prescribed to the patients of 60 or above after being diagnosed with hypophosphatemia during the same month?
### 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 = 'hypophosphatemia') AS t1 JOIN (SELECT patient.uniquepid, medication.drugname, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE patient.age >= 60) 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:
how many patients until 1 year ago have undergone cultures - csf within 2 months after the cardiac angiography - left heart procedure?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'cardiac angiography - left heart' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'cultures - csf' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-1 year')) AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t2.treatmenttime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month')
|
### Instruction:
how much does patient 021-80293's heartrate differ from the second value measured on the current icu visit compared to the first value measured on the current icu visit?
### Response:
|
SELECT (SELECT vitalperiodic.heartrate FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-80293') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1 OFFSET 1) - (SELECT vitalperiodic.heartrate FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-80293') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.observationtime LIMIT 1)
|
### Instruction:
i'd like a round trip ticket from LOS ANGELES to TACOMA WASHINGTON
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare, state WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'TACOMA' AND NOT fare.round_trip_cost IS NULL AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.to_airport = AIRPORT_SERVICE_1.airport_code AND state.state_code = CITY_1.state_code AND state.state_name = 'WASHINGTON') AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'LOS ANGELES' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
All posts with two tags.
### Response:
|
WITH Posts_WITH_Tag1 AS (SELECT Posts.Title AS title, Posts.Tags AS tags, p.PostId AS PostId, (1. * (COUNT(*) OVER (PARTITION BY 1))) AS cnt FROM PostTags AS p JOIN Tags AS t ON t.Id = p.TagId JOIN Posts AS posts ON Posts.Id = p.PostId WHERE t.TagName = '##FirstTag:string##'), Posts_WITH_Tag2 AS (SELECT p.PostId AS PostId, (1. * (COUNT(*) OVER (PARTITION BY 1))) AS cnt FROM PostTags AS p JOIN Tags AS t ON t.Id = p.TagId WHERE t.TagName = '##SecondTag:string##'), Posts_WITH_Both AS (SELECT p1.Title AS title, p1.Tags AS tags, p1.PostId AS PostID, (1. * (COUNT(*) OVER (PARTITION BY 1))) AS cnt FROM Posts_WITH_Tag1 AS p1 INNER JOIN Posts_WITH_Tag2 AS p2 ON p1.PostId = p2.PostId) SELECT * FROM Posts_WITH_Both
|
### Instruction:
make a count of the patients who received stress ulcer prophylaxis - pantoprazole in the same month after having been diagnosed with hypoxemia since 2102.
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'hypoxemia' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2102') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'stress ulcer prophylaxis - pantoprazole' AND STRFTIME('%y', treatment.treatmenttime) >= '2102') AS t2 WHERE t1.diagnosistime < t2.treatmenttime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month')
|
### Instruction:
is patient 25696's urea nitrogen last measured on the last hospital visit greater than second to last measured on the last hospital visit?
### Response:
|
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25696 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'urea nitrogen') ORDER BY labevents.charttime DESC LIMIT 1) > (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25696 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'urea nitrogen') ORDER BY labevents.charttime DESC LIMIT 1 OFFSET 1)
|
### Instruction:
Search Raymond Hettinger / Alex Martelli's Questions & Answers for a Text string. Text searches use a % wildcard by default; searches are case-insensitive. Search Raymond Hettinger / Alex Martelli's Questions & Answers for a Text string. Text searches use a % wildcard by default; searches are case-insensitive
### Response:
|
SELECT Posts.Id AS "post_link", Posts.OwnerUserId AS "author", Posts.PostTypeId AS "post_type", Posts.Score AS "score", Posts.Tags AS "tagged_with" FROM Posts WHERE ((Posts.OwnerUserId = 1001643) OR (Posts.OwnerUserId = 95810)) AND ((LOWER(Posts.Tags) LIKE LOWER('%<##Text##>%')) OR (LOWER(Posts.Title) LIKE LOWER('%##Text##%')) OR (LOWER(Posts.Body) LIKE LOWER('%##Text##%'))) GROUP BY Posts.Id, Posts.OwnerUserId, Posts.PostTypeId, Posts.Score, Posts.Tags ORDER BY Posts.PostTypeId, Posts.Score DESC
|
### Instruction:
Average Response Time for Specific Tags.
### Response:
|
SELECT T.TagName, COUNT(P.Id) AS TotalQuestionsAsked, AVG(CAST((((DATEDIFF(year, P.CreationDate, CreationDate) * 365 + DATEDIFF(day, P.CreationDate, CreationDate)) * 24 + DATEDIFF(hour, P.CreationDate, CreationDate)) * 60 + DATEDIFF(minute, P.CreationDate, CreationDate)) * 60 + DATEDIFF(second, P.CreationDate, CreationDate) AS FLOAT)) / (60 * 60 * 24) AS TimeAvgInDays FROM Posts AS P INNER JOIN Posts AS A ON P.AcceptedAnswerId = A.Id INNER JOIN PostTags AS PT ON P.Id = PT.PostId INNER JOIN Tags AS T ON T.Id = PT.TagId WHERE P.PostTypeId = 1 AND (T.TagName = 'docker') AND NOT P.AcceptedAnswerId IS NULL AND P.CreationDate > '2015-01-01 00:00:00' GROUP BY T.TagName
|
### Instruction:
what is the difference between patient 78131's bicarbonate second measured on the first hospital visit compared to the value first measured on the first hospital visit?
### Response:
|
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 78131 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'bicarbonate') ORDER BY labevents.charttime LIMIT 1 OFFSET 1) - (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 78131 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'bicarbonate') ORDER BY labevents.charttime LIMIT 1)
|
### Instruction:
show me the flights from SALT LAKE CITY to ST. PETERSBURG on wednesday
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, date_day, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ST. PETERSBURG' AND date_day.day_number = 23 AND date_day.month_number = 4 AND date_day.year = 1991 AND days.day_name = date_day.day_name AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SALT LAKE CITY' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
what is the price of a FIRST class ticket from ATLANTA to SAN FRANCISCO
### Response:
|
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, fare_basis, flight, flight_fare WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'ATLANTA' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND fare_basis.class_type = 'FIRST' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
|
### Instruction:
how many patients have undergone glucocorticoids - dexamethasone in the same month in 2102 after the previous procedure of vte prophylaxis - compression boots?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'vte prophylaxis - compression boots' AND STRFTIME('%y', treatment.treatmenttime) = '2102') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'glucocorticoids - dexamethasone' AND STRFTIME('%y', treatment.treatmenttime) = '2102') AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.treatmenttime, 'start of month')
|
### Instruction:
calculate the probability of survival for three year among the patients diagnosed with wound infection - traumatic wound.
### Response:
|
SELECT SUM(CASE WHEN patient.hospitaldischargestatus = 'alive' THEN 1 WHEN STRFTIME('%j', patient.hospitaldischargetime) - STRFTIME('%j', t2.diagnosistime) > 3 * 365 THEN 1 ELSE 0 END) * 100 / COUNT(*) FROM (SELECT t1.uniquepid, t1.diagnosistime FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'wound infection - traumatic wound' GROUP BY patient.uniquepid HAVING MIN(diagnosis.diagnosistime) = diagnosis.diagnosistime) AS t1 WHERE STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', t1.diagnosistime) > 3 * 365) AS t2 JOIN patient ON t2.uniquepid = patient.uniquepid
|
### Instruction:
Users with first-day closure and welcome comment.
### Response:
|
SELECT udfp.OwnerUserId, COUNT(ph.Id) AS numclosures FROM (SELECT p.OwnerUserId, MIN(p.CreationDate) AS dfp FROM Posts AS p WHERE p.PostTypeId < 3 GROUP BY p.OwnerUserId) AS udfp LEFT OUTER JOIN Posts AS p ON p.OwnerUserId = udfp.OwnerUserId AND p.PostTypeId < 3 LEFT OUTER JOIN Comments AS c ON UPPER(c.Text) LIKE '%WELCOME%' AND c.PostId = p.Id AND CAST((JULIANDAY(CreationDate) - JULIANDAY(udfp.dfp)) AS INT) < 24 LEFT OUTER JOIN PostHistory AS ph ON ph.PostHistoryTypeId = 10 AND ph.PostId = p.Id AND CAST((JULIANDAY(CreationDate) - JULIANDAY(udfp.dfp)) AS INT) < 24 GROUP BY udfp.OwnerUserId HAVING COUNT(ph.Id) > 0 AND COUNT(c.Id) > 0 ORDER BY COUNT(ph.Id) DESC
|
### Instruction:
how many patients received chest x-ray within 2 months after being diagnosed with hypoxemia 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 = 'hypoxemia' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'chest x-ray' AND DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-2 year')) AS t2 WHERE t1.diagnosistime < t2.treatmenttime AND DATETIME(t2.treatmenttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month')
|
### Instruction:
how many patients have received nitroglycerin since 6 years ago within the same hospital visit after receiving anticonvulsant - gabapentin?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'anticonvulsant - gabapentin' AND DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-6 year')) AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'nitroglycerin' AND DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-6 year')) AS t2 WHERE t1.treatmenttime < t2.treatmenttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
|
### Instruction:
how many patients since 2105 were diagnosed with diabetes mellitus during the same month after the first diagnosis with stroke - ischemic stroke?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'diabetes mellitus' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2105') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'stroke - ischemic stroke' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2105') AS t2 WHERE t1.diagnosistime < t2.diagnosistime AND DATETIME(t1.diagnosistime, 'start of month') = DATETIME(t2.diagnosistime, 'start of month')
|
### Instruction:
Mean rep gained on posts created on that month.
### Response:
|
SELECT DATEFROMPARTS(TIME_TO_STR(Posts.CreationDate, '%Y'), TIME_TO_STR(Posts.CreationDate, '%M'), 1) AS Month, SUM(CASE WHEN Votes.VoteTypeId = 1 THEN 17 WHEN Posts.PostTypeId = 1 AND Votes.VoteTypeId = 2 THEN 5 WHEN Posts.PostTypeId = 1 AND Votes.VoteTypeId = 3 THEN -2 WHEN Posts.PostTypeId = 2 AND Votes.VoteTypeId = 2 THEN 10 WHEN Posts.PostTypeId = 2 AND Votes.VoteTypeId = 3 THEN -3 ELSE 0 END) AS Rep FROM Posts, Votes WHERE Votes.PostId = Posts.Id AND Votes.VoteTypeId BETWEEN 1 AND 3 AND Posts.PostTypeId BETWEEN 1 AND 2 GROUP BY DATEFROMPARTS(TIME_TO_STR(Posts.CreationDate, '%Y'), TIME_TO_STR(Posts.CreationDate, '%M'), 1) ORDER BY Month DESC
|
### Instruction:
compared to last measured on the current icu visit, is heartrate of patient 017-16041 less than second to last measured on the current icu visit?
### Response:
|
SELECT (SELECT vitalperiodic.heartrate FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '017-16041') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1) < (SELECT vitalperiodic.heartrate FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '017-16041') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1 OFFSET 1)
|
### Instruction:
what are the top five most common diagnoses that patients were diagnosed with within the same month after receiving glucocorticoids - prednisolone's?
### 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 = 'glucocorticoids - prednisolone') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosisname, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid) 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 <= 5
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.