instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: what is the number of patients who had been diagnosed with comp-oth cardiac device since 2105? ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT diagnoses_icd.hadm_id FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'comp-oth cardiac device') AND STRFTIME('%y', diagnoses_icd.charttime) >= '2105')
### Instruction: User List: Top N - Australia - with false positive exclusions. ### Response:
SELECT ROW_NUMBER() OVER (ORDER BY Reputation DESC) AS "#", Id AS "user_link", Reputation, Location, LastAccessDate, UpVotes, DownVotes FROM Users WHERE (LOWER(Location) LIKE LOWER('%Australia%') OR LOWER(Location) LIKE LOWER('%##AbbreviationRight##')) AND NOT (LOWER(Location) = LOWER('Australia') OR LOWER(Location) LIKE LOWER('%Adelaid%') OR LOWER(Location) = LOWER('##location##')) ORDER BY Location LIMIT 100
### Instruction: what the first height of patient 004-86136 in 08/this year. ### Response:
SELECT patient.admissionheight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '004-86136') AND NOT patient.admissionheight IS NULL AND DATETIME(patient.unitadmittime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', patient.unitadmittime) = '08' ORDER BY patient.unitadmittime LIMIT 1
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, return a bar chart about the distribution of hire_date and the average of employee_id bin hire_date by weekday, and rank by the total number in desc. ### Response:
SELECT HIRE_DATE, AVG(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY AVG(EMPLOYEE_ID) DESC
### Instruction: what was the first time patient 28959 had the maximum platelet count value until 06/2103? ### Response:
SELECT labevents.charttime FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 28959) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'platelet count') AND STRFTIME('%y-%m', labevents.charttime) <= '2103-06' ORDER BY labevents.valuenum DESC, labevents.charttime LIMIT 1
### Instruction: when has patient 006-232560 gotten a prescription for the last time in 08/2104? ### Response:
SELECT medication.drugstarttime FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-232560')) AND STRFTIME('%y-%m', medication.drugstarttime) = '2104-08' ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: What is the id and name of the department store that has both marketing and managing department? ### Response:
SELECT T2.dept_store_id, T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "marketing" INTERSECT SELECT T2.dept_store_id, T2.store_name FROM departments AS T1 JOIN department_stores AS T2 ON T1.dept_store_id = T2.dept_store_id WHERE T1.department_name = "managing"
### Instruction: in their last hospital encounter patient 005-26011 was diagnosed with a pleural effusion - etiology unknown? ### Response:
SELECT COUNT(*) > 0 FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '005-26011' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND diagnosis.diagnosisname = 'pleural effusion - etiology unknown'
### Instruction: tell me the name of the specimen test that patient 031-19622 had last received during the last hospital visit? ### Response:
SELECT microlab.culturesite FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-19622' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) ORDER BY microlab.culturetakentime DESC LIMIT 1
### Instruction: i'd like to arrange a trip to BALTIMORE on 1 1 ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service, city, date_day, days, flight WHERE city.city_code = airport_service.city_code AND city.city_name = 'BALTIMORE' AND date_day.day_number = 1 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.airport_code
### Instruction: what did patient 91768 receive for his or her first procedure until 2103? ### Response:
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT procedures_icd.icd9_code FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 91768) AND STRFTIME('%y', procedures_icd.charttime) <= '2103' ORDER BY procedures_icd.charttime LIMIT 1)
### Instruction: Does Christopher Peterson provide teaching for any upper-level courses ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN offering_instructor ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE instructor.name LIKE '%Christopher Peterson%' AND program_course.category LIKE 'ULCS'
### Instruction: Show the hours of the day a user is most active. Gets the hours in which a user has been active (enables you to see when a user sleeps!) ### Response:
WITH hours AS (SELECT TIME_TO_STR(CreationDate, '%I') AS HoursSeen FROM Posts WHERE OwnerUserId = '##UserId##' UNION ALL SELECT TIME_TO_STR(CreationDate, '%I') AS HoursSeen FROM Comments WHERE UserId = '##UserId##') SELECT HoursSeen AS Hour, COUNT(*) AS Count, '|' + REPEAT('*', COUNT(*)) AS Graph FROM hours GROUP BY HoursSeen ORDER BY HoursSeen
### Instruction: Non-CW posts with most revisions counting towards limit. ### Response:
SELECT Posts.Id AS "post_link", COUNT(DISTINCT RevisionGUID) AS Revisions FROM PostHistory JOIN Posts ON PostHistory.PostId = Posts.Id WHERE Posts.CommunityOwnedDate IS NULL AND Posts.OwnerUserId = '##UserId##' AND PostHistory.PostHistoryTypeId IN (1, 2, 3, 4, 5, 6, 7, 8, 9) GROUP BY Posts.Id HAVING COUNT(DISTINCT RevisionGUID) > 2 ORDER BY COUNT(DISTINCT RevisionGUID) DESC
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, find job_id and the sum of employee_id , and group by attribute job_id, and visualize them by a bar chart, and could you show bar in descending order please? ### Response:
SELECT JOB_ID, SUM(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY JOB_ID DESC
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, show me about the distribution of hire_date and the average of department_id bin hire_date by weekday in a bar chart, list by the the average of department id in desc. ### Response:
SELECT HIRE_DATE, AVG(DEPARTMENT_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY AVG(DEPARTMENT_ID) DESC
### Instruction: when has patient 005-87465 received the last systemic antibiotics - vancomycin during their current hospital encounter? ### Response:
SELECT treatment.treatmenttime FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '005-87465' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'systemic antibiotics - vancomycin' ORDER BY treatment.treatmenttime DESC LIMIT 1
### Instruction: what's the name of the drug that patient 41393's been prescribed two or more times until 03/2103? ### Response:
SELECT t1.drug FROM (SELECT prescriptions.drug, COUNT(prescriptions.startdate) AS c1 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 41393) AND STRFTIME('%y-%m', prescriptions.startdate) <= '2103-03' GROUP BY prescriptions.drug) AS t1 WHERE t1.c1 >= 2
### Instruction: how many times did patient 012-4131 make a urine catheter out during their first hospital encounter? ### Response:
SELECT COUNT(*) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '012-4131' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND intakeoutput.cellpath LIKE '%output%' AND intakeoutput.celllabel = 'urine catheter'
### Instruction: Comments where Users can't spell my Alias. ### Response:
SELECT C.Id, C.Text FROM dbo.Posts AS P JOIN dbo.Comments AS C ON P.Id = C.PostId JOIN dbo.Users AS U ON P.OwnerUserId = U.Id WHERE C.CreationDate >= '20180101' AND U.DisplayName != 'Lamu' AND C.Text LIKE '%@Lamu%' AND NOT EXISTS(SELECT 1 FROM dbo.Comments AS Csq JOIN dbo.Users AS Usq ON Csq.UserId = Usq.Id WHERE U.DisplayName = 'Lamu' AND C.PostId = P.Id)
### Instruction: since 1 year ago, what are the four most frequently ordered medications for patients of age 30s? ### Response:
SELECT t1.drugname FROM (SELECT medication.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 30 AND 39) AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-1 year') GROUP BY medication.drugname) AS t1 WHERE t1.c1 <= 4
### Instruction: When Prof. Michelle Kees teaches UKRAINE 451 , does it have a lab ? ### Response:
SELECT COUNT(*) = 0 FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN offering_instructor ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN instructor ON offering_instructor.instructor_id = instructor.instructor_id WHERE course.department = 'UKRAINE' AND course.has_lab = 'N' AND course.number = 451 AND instructor.name LIKE '%Michelle Kees%'
### Instruction: Find coincident activity between two users. ### Response:
WITH Interesting(UserId) AS (SELECT 342852 UNION ALL SELECT 57611) SELECT PostId = p.Id, QuestionId = COALESCE(a.Id, p.Id), AnswerId = CASE WHEN p.PostTypeId = 2 THEN p.Id ELSE NULL END FROM Posts AS p LEFT JOIN Posts AS a ON p.PostTypeId = 2 AND p.ParentId = a.Id WHERE EXISTS(SELECT * FROM Interesting AS i WHERE p.OwnerUserId = i.UserId) OR EXISTS(SELECT * FROM Interesting AS i WHERE a.OwnerUserId = i.UserId)
### Instruction: Getting all linked posts with java tag. ### Response:
SELECT l.Id, l.PostId AS q1Id, r.Tags, r.PostTypeId AS PostTypeId, r.Title AS q1Title, r.Body AS q1Body, l.RelatedPostId AS q2Id, p.Title AS q2Title, p.Body AS q2Body, LinkTypeId AS type FROM PostLinks AS l JOIN Posts AS r ON r.Id = l.PostId JOIN Posts AS p ON p.Id = l.RelatedPostId WHERE p.Tags = 'java' AND r.Tags = 'java' AND l.Id > 1 ORDER BY l.Id LIMIT 10
### Instruction: what was the last intake that patient 009-1746 had received on the first icu visit? ### Response:
SELECT intakeoutput.celllabel FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '009-1746') AND NOT patient.unitdischargetime IS NULL ORDER BY patient.unitadmittime LIMIT 1) AND intakeoutput.cellpath LIKE '%intake%' ORDER BY intakeoutput.intakeoutputtime DESC LIMIT 1
### Instruction: the number of times patient 1232 had had a arterial catheterization procedure during their first hospital encounter. ### Response:
SELECT COUNT(*) FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'arterial catheterization') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 1232 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1)
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, visualize a bar chart about the distribution of hire_date and the sum of department_id bin hire_date by weekday, I want to sort from high to low by the sum department id. ### Response:
SELECT HIRE_DATE, SUM(DEPARTMENT_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY SUM(DEPARTMENT_ID) DESC
### Instruction: Which upper level courses does Loch-caruso teach ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN offering_instructor ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE instructor.name LIKE '%Loch-caruso%' AND program_course.category LIKE 'ULCS'
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, return a bar chart about the distribution of hire_date and the sum of employee_id bin hire_date by weekday, and list by the total number from high to low. ### Response:
SELECT HIRE_DATE, SUM(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY SUM(EMPLOYEE_ID) DESC
### Instruction: For GREEK 560 , is GREEK 801 a prerequisite ? ### Response:
SELECT COUNT(*) > 0 FROM course AS COURSE_0, course AS COURSE_1, course_prerequisite WHERE COURSE_0.course_id = course_prerequisite.pre_course_id AND COURSE_0.department = 'GREEK' AND COURSE_0.number = 801 AND COURSE_1.course_id = course_prerequisite.course_id AND COURSE_1.department = 'GREEK' AND COURSE_1.number = 560
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, a bar chart shows the distribution of job_id and the sum of department_id , and group by attribute job_id, I want to display in desc by the sum department id. ### Response:
SELECT JOB_ID, SUM(DEPARTMENT_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY SUM(DEPARTMENT_ID) DESC
### Instruction: how many days has it taken since the first time patient 003-10080 had a procedure in this hospital visit? ### Response:
SELECT 1 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', treatment.treatmenttime)) FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '003-10080' AND patient.hospitaldischargetime IS NULL)) ORDER BY treatment.treatmenttime LIMIT 1
### Instruction: subjects must have an admission blood glucose > 140 mg and < 400 mg / dl without laboratory evidence of diabetic ketoacidosis ( serum bicarbonate < 18 meq / l or positive serum or urinary ketones ) . ### Response:
SELECT * FROM table_dev_4 WHERE admission_blood_glucose > 140 AND admission_blood_glucose < 400 OR (diabetic_ketoacidosis = 0 OR serum_bicarbonate < 18 OR positive_serum = 1 OR urinary_ketones = 1)
### Instruction: bisacodyl or heparin sodium or 0.9% sodium chloride (mini bag plus) have been ordered for patient 21110 in 2105? ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 21110) AND prescriptions.drug IN ('bisacodyl', 'heparin sodium', '0.9% sodium chloride (mini bag plus)') AND STRFTIME('%y', prescriptions.startdate) = '2105'
### Instruction: had patient 018-95228 received any laboratory test in 08/last year? ### Response:
SELECT COUNT(*) > 0 FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '018-95228')) AND DATETIME(lab.labresulttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', lab.labresulttime) = '08'
### Instruction: what was the yearly average intake of d5w of patient 030-51920? ### Response:
SELECT AVG(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 = '030-51920')) AND intakeoutput.celllabel = 'd5w' AND intakeoutput.cellpath LIKE '%intake%' GROUP BY STRFTIME('%y', intakeoutput.intakeoutputtime)
### Instruction: DBA - Total Posts by Database Server Per Month - PostgreSQL. ### Response:
SELECT CONCAT(YEAR(P.CreationDate), '-', MONTH(P.CreationDate)) AS YearMonth, 'PostgreSQL' AS TagName, COUNT(*) AS PostCount FROM Posts AS P INNER JOIN PostTags AS PT ON (P.Id = PT.PostId) INNER JOIN Tags AS T ON (PT.TagId = T.Id) WHERE T.TagName LIKE 'postgresql%' GROUP BY YEAR(P.CreationDate), MONTH(P.CreationDate) ORDER BY YEAR(P.CreationDate) DESC, MONTH(P.CreationDate) DESC
### Instruction: what is the first value of the sodium lab test of patient 006-14121 since 12/2105? ### Response:
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 = '006-14121')) AND lab.labname = 'sodium' AND STRFTIME('%y-%m', lab.labresulttime) >= '2105-12' ORDER BY lab.labresulttime LIMIT 1
### Instruction: when until 6 months ago did patient 031-9128 get the last microbiology test? ### Response:
SELECT microlab.culturetakentime FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-9128')) AND DATETIME(microlab.culturetakentime) <= DATETIME(CURRENT_TIME(), '-6 month') ORDER BY microlab.culturetakentime DESC LIMIT 1
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, give me the comparison about the sum of salary over the job_id , and group by attribute job_id by a bar chart, I want to rank by the sum salary in descending please. ### Response:
SELECT JOB_ID, SUM(SALARY) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY SUM(SALARY) DESC
### Instruction: Who is going to teach Stage Management for this semester ? ### Response:
SELECT DISTINCT instructor.name FROM instructor INNER JOIN offering_instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN course_offering ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN course ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE course.name LIKE '%Stage Management%' AND semester.semester = 'WN' AND semester.year = 2016
### Instruction: list patient 29741's monthly minimum pt the last year. ### Response:
SELECT MIN(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 29741) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'pt') AND DATETIME(labevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY STRFTIME('%y-%m', labevents.charttime)
### Instruction: total sql questions and AcceptedAnswers my month. ### Response:
WITH t1 AS (SELECT TIME_TO_STR(p.CreationDate, '%Y') AS Year, TIME_TO_STR(p.CreationDate, '%m') AS Month, COUNT(*) AS total, COUNT(AcceptedAnswerId) AS AcceptedAnswers FROM Posts AS p WHERE Tags LIKE '%<sql>%' GROUP BY TIME_TO_STR(p.CreationDate, '%Y'), TIME_TO_STR(p.CreationDate, '%m')) SELECT DATE(CONCAT(Year, '-', Month, '-01')), total, AcceptedAnswers FROM t1 ORDER BY 1
### Instruction: when was patient 97330 last having the maximum epithelial cells level since 16 months ago? ### Response:
SELECT labevents.charttime FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 97330) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'epithelial cells') AND DATETIME(labevents.charttime) >= DATETIME(CURRENT_TIME(), '-16 month') ORDER BY labevents.valuenum DESC, labevents.charttime DESC LIMIT 1
### Instruction: Score per answer (ranking; non-CW). ### Response:
SELECT RANK() OVER (ORDER BY R.Ratio DESC) AS Rank, R.Id AS "user_link", R.Ratio FROM (SELECT U.Id, CAST(SUM(A.Score) AS FLOAT) / COUNT(A.Score) AS Ratio FROM Posts AS A INNER JOIN Users AS U ON U.Id = A.OwnerUserId WHERE A.PostTypeId = 2 AND A.CommunityOwnedDate IS NULL GROUP BY U.Id HAVING COUNT(A.Id) >= '##MinimumAnswerCount?400##') AS R ORDER BY R.Ratio DESC
### Instruction: What papers have Richard Ladner and Linda Shapiro written ? ### Response:
SELECT DISTINCT WRITES_0.paperid FROM author AS AUTHOR_0, author AS AUTHOR_1, writes AS WRITES_0, writes AS WRITES_1 WHERE AUTHOR_0.authorname = 'Richard Ladner' AND AUTHOR_1.authorname = 'Linda Shapiro' AND WRITES_0.authorid = AUTHOR_0.authorid AND WRITES_1.authorid = AUTHOR_1.authorid AND WRITES_1.paperid = WRITES_0.paperid
### Instruction: list nonstop flights from BWI washington airport to OAKLAND that depart in the afternoon ### Response:
SELECT DISTINCT flight.flight_id FROM airport, airport_service, city, flight WHERE ((airport.airport_code = 'BWI' AND city.city_code = airport_service.city_code AND city.city_name = 'OAKLAND' AND flight.from_airport = airport.airport_code AND flight.to_airport = airport_service.airport_code) AND flight.departure_time BETWEEN 1200 AND 1800) AND flight.stops = 0
### Instruction: what was the total amount of promote w/fiber intake that patient 11914 had? ### Response:
SELECT SUM(inputevents_cv.amount) FROM inputevents_cv WHERE inputevents_cv.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 11914)) AND inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'promote w/fiber' AND d_items.linksto = 'inputevents_cv')
### Instruction: in 2102, what are the top five most common procedures? ### Response:
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT t1.icd9_code FROM (SELECT procedures_icd.icd9_code, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM procedures_icd WHERE STRFTIME('%y', procedures_icd.charttime) = '2102' GROUP BY procedures_icd.icd9_code) AS t1 WHERE t1.c1 <= 5)
### Instruction: Number of posts per year scoring more or less then a threshold. Input: threshold; post type. ### Response:
WITH sqx_cte(q_year, more_less, q_count) AS (SELECT YEAR(p.CreationDate) AS q_year, CASE WHEN p.Score >= @ThresholdScore THEN 'M' ELSE 'L' END AS more_less, COUNT(1) AS q_count FROM Posts AS p WHERE p.PostTypeId = @PostTypeId GROUP BY YEAR(p.CreationDate), CASE WHEN p.Score >= @ThresholdScore THEN 'M' ELSE 'L' END) SELECT * FROM sqx_cte ORDER BY q_year, more_less
### Instruction: what is the maximum hospital cost that involves a procedure, called electrolyte administration - oral in 2105? ### Response:
SELECT MAX(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT treatment.patientunitstayid FROM treatment WHERE treatment.treatmentname = 'electrolyte administration - oral')) AND STRFTIME('%y', cost.chargetime) = '2105' GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: what is the minimum sao2 of patient 030-52327 since 688 days ago? ### Response:
SELECT MIN(vitalperiodic.sao2) FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '030-52327')) AND NOT vitalperiodic.sao2 IS NULL AND DATETIME(vitalperiodic.observationtime) >= DATETIME(CURRENT_TIME(), '-688 day')
### Instruction: when has patient 22315 received the last opn/oth rep aort vlv-tis? ### Response:
SELECT procedures_icd.charttime FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'opn/oth rep aort vlv-tis') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 22315) ORDER BY procedures_icd.charttime DESC LIMIT 1
### Instruction: tell me the minimum hospital cost that includes feeding tube - gastrostomy since 2105? ### Response:
SELECT MIN(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT treatment.patientunitstayid FROM treatment WHERE treatment.treatmentname = 'feeding tube - gastrostomy')) AND STRFTIME('%y', cost.chargetime) >= '2105' GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: tell me the name of the last specimen test that patient 4758 in 07/this year received? ### Response:
SELECT microbiologyevents.spec_type_desc FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 4758) AND DATETIME(microbiologyevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', microbiologyevents.charttime) = '07' ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: when was the last time since 179 months ago that patient 1114 had the maximum magnesium? ### Response:
SELECT labevents.charttime FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 1114) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'magnesium') AND DATETIME(labevents.charttime) >= DATETIME(CURRENT_TIME(), '-179 month') ORDER BY labevents.valuenum DESC, labevents.charttime DESC LIMIT 1
### Instruction: among patients of age 50s during the previous year, what were the top four most frequent lab tests? ### Response:
SELECT t1.labname FROM (SELECT lab.labname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 50 AND 59) AND DATETIME(lab.labresulttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY lab.labname) AS t1 WHERE t1.c1 <= 4
### Instruction: among those with age 40s in 2101 what was the top four most frequent diagnosis? ### Response:
SELECT t1.diagnosisname FROM (SELECT diagnosis.diagnosisname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 40 AND 49) AND STRFTIME('%y', diagnosis.diagnosistime) = '2101' GROUP BY diagnosis.diagnosisname) AS t1 WHERE t1.c1 <= 4
### Instruction: what is the average total cost of a hospital that includes laboratory testing for alkaline phos. since 2105? ### Response:
SELECT AVG(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT lab.patientunitstayid FROM lab WHERE lab.labname = 'alkaline phos.')) AND STRFTIME('%y', cost.chargetime) >= '2105' GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, show me about the distribution of hire_date and the sum of employee_id bin hire_date by time in a bar chart, and rank total number from low to high order. ### Response:
SELECT HIRE_DATE, SUM(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY SUM(EMPLOYEE_ID)
### Instruction: did patient 017-49538's sao2, on the current icu visit, have been normal? ### Response:
SELECT COUNT(*) > 0 FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '017-49538') AND patient.unitdischargetime IS NULL) AND vitalperiodic.sao2 BETWEEN sao2_lower AND sao2_upper AND NOT vitalperiodic.sao2 IS NULL
### Instruction: get me the top four most frequently prescribed drugs for patients 60 or above during this year? ### Response:
SELECT t1.drug FROM (SELECT prescriptions.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.age >= 60) AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') GROUP BY prescriptions.drug) AS t1 WHERE t1.c1 <= 4
### Instruction: Count of active answerers by week. Count of the users posted at least 3 answers on that week ### Response:
WITH Raw AS (SELECT Id, DATEADD(day, 7 * (DATEDIFF(day, '1970-01-05', CreationDate) / 7), '1970-01-05') AS Week, OwnerUserId AS UserId FROM Posts WHERE PostTypeId = 2 AND OwnerUserId > 0), Raw2 AS (SELECT Week, UserId, COUNT(*) AS PostCount FROM Raw GROUP BY Week, UserId) SELECT Week, COUNT(*) AS UserCount FROM Raw2 WHERE PostCount > 3 GROUP BY Week ORDER BY Week
### Instruction: what is the total average cost of a hospital that includes a promyelocytes lab test in the last year? ### Response:
SELECT AVG(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.hadm_id IN (SELECT labevents.hadm_id FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'promyelocytes')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY cost.hadm_id) AS t1
### Instruction: what paper did ras bodik and ameet soni write together ? ### Response:
SELECT DISTINCT WRITES_0.paperid FROM author AS AUTHOR_0, author AS AUTHOR_1, writes AS WRITES_0, writes AS WRITES_1 WHERE AUTHOR_0.authorname = 'ras bodik' AND AUTHOR_1.authorname = 'ameet soni' AND WRITES_0.authorid = AUTHOR_0.authorid AND WRITES_1.authorid = AUTHOR_1.authorid AND WRITES_1.paperid = WRITES_0.paperid
### Instruction: when was the first time that patient 015-91239 had the maximum value of respiration on the current icu visit? ### Response:
SELECT vitalperiodic.observationtime FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '015-91239') AND patient.unitdischargetime IS NULL) AND NOT vitalperiodic.respiration IS NULL ORDER BY vitalperiodic.respiration DESC, vitalperiodic.observationtime LIMIT 1
### Instruction: was there any organism detected in patient 10811's last stool microbiological test until 01/2104? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 10811) AND microbiologyevents.spec_type_desc = 'stool' AND NOT microbiologyevents.org_name IS NULL AND STRFTIME('%y-%m', microbiologyevents.charttime) <= '2104-01' ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: What is the average tourism receipts in millions of US dollars in 2011 with less than 1.141 million of 2011 tourist arrivals and more than 1,449 tourism receipts in 2011 US dollars per arrival? ### Response:
SELECT AVG(tourism_receipts__2011___millions_of_us) AS $_ FROM table_name_41 WHERE tourist_arrivals__2011___millions_ < 1.141 AND tourism_receipts__2011___us$_per_arrival_ > 1 OFFSET 449
### Instruction: when did patient 029-16431 have a base excess test for the last time when they came to the hospital last time? ### Response:
SELECT lab.labresulttime FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '029-16431' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND lab.labname = 'base excess' ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: what was patient 005-48105's heartrate average today? ### Response:
SELECT AVG(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 = '005-48105')) AND NOT vitalperiodic.heartrate IS NULL AND DATETIME(vitalperiodic.observationtime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-0 day')
### Instruction: For NESLANG 451 is NESLANG 499 required ? ### Response:
SELECT COUNT(*) > 0 FROM course AS COURSE_0, course AS COURSE_1, course_prerequisite WHERE COURSE_0.course_id = course_prerequisite.pre_course_id AND COURSE_0.department = 'NESLANG' AND COURSE_0.number = 499 AND COURSE_1.course_id = course_prerequisite.course_id AND COURSE_1.department = 'NESLANG' AND COURSE_1.number = 451
### Instruction: what is the monthly minimum effluent output that patient 035-3496 has had? ### Response:
SELECT MIN(intakeoutput.cellvaluenumeric) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '035-3496')) AND intakeoutput.celllabel = 'effluent' AND intakeoutput.cellpath LIKE '%output%' GROUP BY STRFTIME('%y-%m', intakeoutput.intakeoutputtime)
### Instruction: what was the maximum monthly number of patients who were admitted for dmii oth nt st uncntrld? ### Response:
SELECT MAX(t1.c1) FROM (SELECT COUNT(DISTINCT diagnoses_icd.hadm_id) AS c1 FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'dmii oth nt st uncntrld') GROUP BY STRFTIME('%y-%m', diagnoses_icd.charttime)) AS t1
### Instruction: Average question score by account age (up to 1 year). ### Response:
SELECT DATEDIFF(DAY, u.CreationDate, CreationDate) AS "Account age (days)", AVG(CAST(p.Score AS FLOAT)) AS "Average score" FROM Posts AS p INNER JOIN Users AS u ON p.OwnerUserId = u.Id WHERE p.PostTypeId = 1 AND DATEDIFF(DAY, u.CreationDate, CreationDate) BETWEEN 0 AND 365 GROUP BY DATEDIFF(DAY, u.CreationDate, CreationDate) ORDER BY DATEDIFF(DAY, u.CreationDate, CreationDate)
### Instruction: what was the last value of a -polys laboratory testing of patient 005-86645 until 21 months ago? ### Response:
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 = '005-86645')) AND lab.labname = '-polys' AND DATETIME(lab.labresulttime) <= DATETIME(CURRENT_TIME(), '-21 month') ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: Seek and Destroy: Comments with the phrase 'not an answer'. A query to help look for non-answers--comments with the phrase 'not an answer' on answers with low score. Flags ahoy! But try not to *completely* overwhelm the poor moderators, 'k? ### Response:
SELECT a.Id AS "post_link", a.Score AS "answer_score", c.Text AS "comment_text", a.Body AS "answer_text", a.CreationDate FROM Comments AS c INNER JOIN Posts AS a ON c.PostId = a.Id AND a.Score < 2 AND c.Text LIKE '%From Review%' ORDER BY a.Score
### Instruction: I 'm trying to find out if CLCIV 499 has morning classes ? ### Response:
SELECT COUNT(*) > 0 FROM course, course_offering, semester WHERE course_offering.start_time < '12:00:00' AND course_offering.start_time >= '08:00:00' AND course.course_id = course_offering.course_id AND course.department = 'CLCIV' AND course.number = 499 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: tell me whether patient 002-13643 been prescribed albumin human 25% since 75 months ago? ### Response:
SELECT COUNT(*) > 0 FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '002-13643')) AND medication.drugname = 'albumin human 25%' AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-75 month')
### Instruction: what were the top three most common diagnoses for patients of the 30s since 2100? ### Response:
SELECT t1.diagnosisname FROM (SELECT diagnosis.diagnosisname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 30 AND 39) AND STRFTIME('%y', diagnosis.diagnosistime) >= '2100' GROUP BY diagnosis.diagnosisname) AS t1 WHERE t1.c1 <= 3
### Instruction: when did patient 9801 first had the drain out #2 jp lateral output? ### Response:
SELECT outputevents.charttime FROM outputevents WHERE outputevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 9801)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'drain out #2 jp lateral' AND d_items.linksto = 'outputevents') ORDER BY outputevents.charttime LIMIT 1
### Instruction: Top Mapbox Stack Overflow Answerers. ### Response:
SELECT au.DisplayName AS "Display name", CAST('https://stackoverflow.com/users/' AS TEXT(32)) + CAST(au.Id AS TEXT(8)) AS "Profile page", COUNT(*) AS "Number of accepted answers" FROM PostTags AS pt JOIN Tags AS t ON pt.TagId = t.Id JOIN Posts AS p ON pt.PostId = p.Id JOIN Posts AS a ON p.AcceptedAnswerId = a.Id JOIN Users AS au ON a.OwnerUserId = au.Id WHERE (t.TagName LIKE '%mapbox%') GROUP BY au.DisplayName, au.Id ORDER BY COUNT(*) DESC
### Instruction: Possible editors for the 'rebol' tag. Lists every user who has ever answered a question on the 'rebol' tag, along with if they have sufficient rep to edit questions ### Response:
SELECT MAX(Users.Reputation), Users.Id AS "user_link", 'can_edit' = CASE WHEN MAX(Users.Reputation) >= 2000 THEN 'yes' ELSE 'no' END FROM Posts, Users, PostTags, Tags WHERE Posts.OwnerUserId = Users.Id AND Posts.ParentId = PostTags.PostId AND PostTags.TagId = Tags.Id AND Tags.TagName = 'rebol' GROUP BY Users.Id ORDER BY MAX(Reputation) DESC
### Instruction: Unanswered questions with a tag favorited by users with a badge in that tag. ### Response:
SELECT p.Id AS "post_link", p.Score, p.CommentCount, p.CreationDate FROM Posts AS p, Badges AS b, Votes AS v WHERE b.Name = '##tag##' AND v.VoteTypeId = 5 AND v.PostId = p.Id AND v.UserId = b.UserId AND p.Tags LIKE '%##tag##%' AND p.AnswerCount = 0 AND p.ClosedDate IS NULL GROUP BY p.Id, p.Score, p.CommentCount, p.CreationDate ORDER BY p.CreationDate DESC
### Instruction: Name the upper level electives that are available next Spring after 12:30 A.M. . ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program_course, semester WHERE course_offering.start_time > '12:30' AND course.course_id = course_offering.course_id AND program_course.category LIKE '%ULCS%' AND program_course.course_id = course.course_id AND semester.semester = 'Spring' AND semester.semester_id = course_offering.semester AND semester.year = 2017
### Instruction: what is the drug that in the last month patient 11362 has been prescribed two or more times? ### Response:
SELECT t1.drug FROM (SELECT prescriptions.drug, COUNT(prescriptions.startdate) AS c1 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 11362) AND DATETIME(prescriptions.startdate, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') GROUP BY prescriptions.drug) AS t1 WHERE t1.c1 >= 2
### Instruction: have patient 013-28507 received a vte prophylaxis - compression stockings since 4 years ago? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '013-28507')) AND treatment.treatmentname = 'vte prophylaxis - compression stockings' AND DATETIME(treatment.treatmenttime) >= DATETIME(CURRENT_TIME(), '-4 year')
### Instruction: what are the top five most frequent laboratory tests among the patients of age 30s during this year? ### Response:
SELECT t1.labname FROM (SELECT lab.labname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 30 AND 39) AND DATETIME(lab.labresulttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') GROUP BY lab.labname) AS t1 WHERE t1.c1 <= 5
### Instruction: tell me the top four most frequently prescribed drugs for patients with an age of 30s since 2101? ### Response:
SELECT t1.drugname FROM (SELECT medication.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 30 AND 39) AND STRFTIME('%y', medication.drugstarttime) >= '2101' GROUP BY medication.drugname) AS t1 WHERE t1.c1 <= 4
### Instruction: when was patient 028-70851 being prescribed with a medication for the first time until 12/2101? ### Response:
SELECT medication.drugstarttime FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '028-70851')) AND STRFTIME('%y-%m', medication.drugstarttime) <= '2101-12' ORDER BY medication.drugstarttime LIMIT 1
### Instruction: what did patient 006-185446 receive for his or her last procedure in a year before? ### Response:
SELECT treatment.treatmentname FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-185446')) AND DATETIME(treatment.treatmenttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') ORDER BY treatment.treatmenttime DESC LIMIT 1
### Instruction: how many days has passed since the first procedure patient 017-45919 has received on the current hospital encounter? ### Response:
SELECT 1 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', treatment.treatmenttime)) FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '017-45919' AND patient.hospitaldischargetime IS NULL)) ORDER BY treatment.treatmenttime LIMIT 1
### Instruction: what's the first value of the -monos lab test of patient 007-9115 in 04/2104? ### Response:
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 = '007-9115')) AND lab.labname = '-monos' AND STRFTIME('%y-%m', lab.labresulttime) = '2104-04' ORDER BY lab.labresulttime LIMIT 1
### Instruction: how many hours have passed since patient 95892 received a pt laboratory test for the first time in this hospital encounter? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', labevents.charttime)) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'pt') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 95892 AND admissions.dischtime IS NULL) ORDER BY labevents.charttime LIMIT 1
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, show me about the distribution of job_id and the sum of employee_id , and group by attribute job_id in a bar chart, sort by the x axis from low to high please. ### Response:
SELECT JOB_ID, SUM(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID ORDER BY JOB_ID
### Instruction: what is the monthly average amount of anion gap patient 69819 has until 1 year ago? ### Response:
SELECT AVG(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 69819) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'anion gap') AND DATETIME(labevents.charttime) <= DATETIME(CURRENT_TIME(), '-1 year') GROUP BY STRFTIME('%y-%m', labevents.charttime)
### Instruction: How many upvotes and downvotes a user has. ### Response:
SELECT UpVotes, DownVotes, COUNT(*) AS AnswersCount FROM (SELECT SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes, SUM(CASE WHEN VoteTypeId = 3 THEN -1 ELSE 0 END) AS DownVotes FROM Posts INNER JOIN Votes ON Votes.PostId = Posts.Id AND (VoteTypeId = 2 OR VoteTypeId = 3) WHERE Posts.OwnerUserId = @UserId GROUP BY Posts.Id) AS VotesCount GROUP BY UpVotes, DownVotes ORDER BY UpVotes DESC
### Instruction: you count the number of times patient 030-40287 has taken a total on the last intensive care unit visit. ### Response:
SELECT COUNT(*) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '030-40287') AND NOT patient.unitdischargetime IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1) AND intakeoutput.cellpath LIKE '%intake%' AND intakeoutput.celllabel = 'total'
### Instruction: Top users (by reputation) in a location by tag. ### Response:
SELECT ROW_NUMBER() OVER (ORDER BY Reputation DESC) AS "#", u.Id AS "user_link", u.Reputation, COUNT(p.Id) AS "questions" FROM Users AS u INNER JOIN Posts AS p ON p.OwnerUserId = u.Id INNER JOIN PostTags AS pt ON pt.PostId = p.Id INNER JOIN Tags AS t ON t.Id = pt.TagId WHERE LOWER(Location) LIKE LOWER('%##countryname##%') AND t.TagName = '##tagname##' GROUP BY u.Id, u.Reputation ORDER BY Reputation DESC
### Instruction: when the last time patient 010-16627 had a hct lab test until 06/2105? ### Response:
SELECT lab.labresulttime FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '010-16627')) AND lab.labname = 'hct' AND STRFTIME('%y-%m', lab.labresulttime) <= '2105-06' ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: Of the upper level courses , which does Atran teach ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN offering_instructor ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE instructor.name LIKE '%Atran%' AND program_course.category LIKE 'ULCS'