instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: How many 300 -level classes are being offered in Fall and Winter term ? ### Response:
SELECT COUNT(DISTINCT course.department, course.name, course.number, semester.semester) FROM course, course_offering, semester WHERE course.course_id = course_offering.course_id AND course.department = 'EECS' AND course.number BETWEEN 300 AND 300 + 100 AND semester.semester IN ('FA', 'WN') AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: what are the top four most common lab tests for patients aged 60 or above, in 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 >= 60) AND DATETIME(lab.labresulttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') GROUP BY lab.labname) AS t1 WHERE t1.c1 <= 4
### Instruction: 100 -level classes , are they offered in the Spring or Summer term ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, semester.semester FROM course, course_offering, semester WHERE course.course_id = course_offering.course_id AND course.department = 'EECS' AND course.number BETWEEN 100 AND 100 + 100 AND semester.semester IN ('SP', 'SS', 'SU') AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: in this year, what is the five most frequently taken lab test for patients of 60 or above? ### 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 >= 60) 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: 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, draw a bar chart about the distribution of hire_date and the average of salary bin hire_date by time, sort by the Y-axis in descending. ### Response:
SELECT HIRE_DATE, AVG(SALARY) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY AVG(SALARY) DESC
### Instruction: what was the average systemicmean on the last icu visit for patient 031-4987. ### Response:
SELECT AVG(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 = '031-4987') AND NOT patient.unitdischargetime IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1) AND NOT vitalperiodic.systemicmean IS NULL
### Instruction: count the number of patients who in 2102 received lingual thyroid excision. ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT procedures_icd.hadm_id FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'lingual thyroid excision') AND STRFTIME('%y', procedures_icd.charttime) = '2102')
### Instruction: what was patient 007-8066 diagnosed with the last time until 1 year ago? ### Response:
SELECT diagnosis.diagnosisname FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '007-8066')) AND DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-1 year') ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: Find all movies featuring ' Jason Robards ' and ' Woody Strode ### Response:
SELECT movie.title FROM actor AS ACTOR_0, actor AS ACTOR_1, cast AS CAST_0, cast AS CAST_1, movie WHERE ACTOR_0.name = 'Woody Strode' AND ACTOR_1.name = 'Jason Robards' AND CAST_0.aid = ACTOR_0.aid AND CAST_1.aid = ACTOR_1.aid AND movie.mid = CAST_0.msid AND movie.mid = CAST_1.msid
### Instruction: How many courses for each course description? Show me a stacked bar chart The x-axis is course description and group by instructor's name, and order from low to high by the y axis. ### Response:
SELECT CRS_DESCRIPTION, COUNT(CRS_DESCRIPTION) FROM CLASS AS T1 JOIN EMPLOYEE AS T2 ON T1.PROF_NUM = T2.EMP_NUM JOIN COURSE AS T3 ON T1.CRS_CODE = T3.CRS_CODE GROUP BY EMP_FNAME, CRS_DESCRIPTION ORDER BY COUNT(CRS_DESCRIPTION)
### Instruction: the number of times that patient 035-166 had been prescribed morphine inj in 04/2104. ### Response:
SELECT COUNT(*) FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '035-166')) AND medication.drugname = 'morphine inj' AND STRFTIME('%y-%m', medication.drugstarttime) = '2104-04'
### Instruction: What 500 -level classes are offered in the Spring or Summer terms ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, semester.semester FROM course, course_offering, semester WHERE course.course_id = course_offering.course_id AND course.department = 'department0' AND course.number BETWEEN 500 AND 500 + 100 AND semester.semester IN ('SP', 'SU', 'SS') AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: Question up/down voting by time. ### Response:
SELECT CAST(DATEADD(week, DATEDIFF(week, @epoch, CreationDate), @epoch) AS DATE) AS week, COUNT(CASE WHEN VoteTypeId = 2 THEN 1 END) * 1.0 / COUNT(*) FROM Posts AS p JOIN Votes AS v ON PostId = p.Id WHERE PostTypeId = 1 AND VoteTypeId IN (2, 3) AND p.CreationDate > @FirstQuestion GROUP BY DATEDIFF(week, @epoch, CreationDate) ORDER BY DATEDIFF(week, @epoch, CreationDate)
### 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 average of salary over the hire_date bin hire_date by time, and I want to sort y-axis in desc order. ### Response:
SELECT HIRE_DATE, AVG(SALARY) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY AVG(SALARY) DESC
### Instruction: The only person who teaches Mini Classical Civilization , is it Prof. Gone ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, instructor.name FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.name LIKE '%Mini Classical Civilization%' AND NOT instructor.name LIKE '%Gone%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: Tags with excerpt but no wiki, or reverse (Sci Fi SE). ### Response:
SELECT t.Count, t.TagName, x.Body AS ExcerptText, d.Body AS WikiText FROM (Tags AS t LEFT JOIN Posts AS x ON t.ExcerptPostId = x.Id) LEFT JOIN Posts AS d ON t.WikiPostId = d.Id WHERE 0 = LENGTH(d.Body) AND 0 < LENGTH(x.Body) OR 0 = LENGTH(x.Body) AND 0 < LENGTH(d.Body) ORDER BY t.Count DESC
### Instruction: what is the average hospital cost that involves a procedure known as a int or repl lead epicar? ### Response:
SELECT AVG(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.hadm_id IN (SELECT procedures_icd.hadm_id FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'int or repl lead epicar')) GROUP BY cost.hadm_id) AS t1
### Instruction: Ten major RDBMS systems, ranked by popularity. ### Response:
SELECT TagName AS Tags, cnt AS "questions_tagged", ROUND(100.0 * cnt / SUM(cnt) OVER (), 2) AS "ratio,_%" FROM Tags AS t JOIN LATERAL (SELECT COUNT(*) AS cnt FROM PostTags AS pt WHERE pt.TagId = t.Id) AS q WHERE t.TagName IN ('mysql', 'sql-server', 'oracle', 'postgresql', 'mariadb', 'mongodb', 'cassandra', 'db2', 'msaccess', 'redis', 'sqlite') ORDER BY cnt DESC
### Instruction: What is the clock multiplier if the voltage range (v) is 3.3 - 3.6; input clock (mhz) is 33 x 3 / 50 x 2; and part number is a80486dx4-100? ### Response:
SELECT "Clock Multiplier" FROM table_1213 WHERE "Voltage Range (V)" = '3.3 - 3.6' AND "Input Clock (MHz)" = '33 X 3 / 50 X 2' AND "Part Number" = 'A80486DX4-100'
### Instruction: in this month, have there been any microbiology tests conducted for patient 025-44495? ### Response:
SELECT COUNT(*) > 0 FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '025-44495')) AND DATETIME(microlab.culturetakentime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month')
### Instruction: Rollbacks by a certain user. ### Response:
WITH RollbackHistory AS (SELECT PostId, CreationDate FROM PostHistory WHERE UserId = @UserId AND PostHistoryTypeId IN (7, 8, 9) GROUP BY PostId, CreationDate, RevisionGUID) SELECT h.PostId AS "post_link", h.CreationDate, p.OwnerUserId AS "user_link", CASE p.PostTypeId WHEN 1 THEN 'Question' WHEN 2 THEN 'Answer' END AS "Post type" FROM RollbackHistory AS h INNER JOIN Posts AS p ON h.PostId = p.Id ORDER BY h.CreationDate DESC
### Instruction: who was diagnosed with legal blindness-usa def until 2 years ago? ### Response:
SELECT 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 = 'legal blindness-usa def') AND DATETIME(diagnoses_icd.charttime) <= DATETIME(CURRENT_TIME(), '-2 year'))
### Instruction: has any microbiological test been performed on patient 025-28600's abscess during their first hospital encounter? ### Response:
SELECT COUNT(*) FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '025-28600' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND microlab.culturesite = 'abscess'
### Instruction: What are MKT 322 's course prerequisite requirements ? ### Response:
SELECT DISTINCT COURSE_1.department, COURSE_1.name, COURSE_1.number FROM course AS COURSE_0 INNER JOIN course_prerequisite ON COURSE_0.course_id = course_prerequisite.course_id INNER JOIN course AS COURSE_1 ON COURSE_1.course_id = course_prerequisite.pre_course_id WHERE COURSE_0.department = 'MKT' AND COURSE_0.number = 322
### Instruction: late answers that are not accepted but most likely have highest score. ### Response:
SELECT COUNT(DISTINCT (q.Id)) FROM Posts AS q INNER JOIN Posts AS a ON a.ParentId = q.Id INNER JOIN Posts AS aa ON aa.ParentId = q.Id WHERE q.PostTypeId = 1 AND a.PostTypeId = 2 AND aa.PostTypeId = 2 AND q.AnswerCount >= 2 AND DATEDIFF(DAY, q.CreationDate, CreationDate) <= 7 AND DATEDIFF(DAY, q.CreationDate, CreationDate) >= 30 AND a.Score < aa.Score
### Instruction: what is the minimum total cost to the hospital that includes a pressure control lab test until 2104? ### 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 lab.patientunitstayid FROM lab WHERE lab.labname = 'pressure control')) AND STRFTIME('%y', cost.chargetime) <= '2104' GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: when did patient 010-33968 have the last heartrate to be greater than 76.0? ### Response:
SELECT vitalperiodic.observationtime FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '010-33968')) AND vitalperiodic.heartrate > 76.0 AND NOT vitalperiodic.heartrate IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1
### Instruction: Average Answer Score by Content Length. Investigating the effects of tl;dr ### Response:
SELECT (LENGTH(Body) / '##ChunkSize:int##') * '##ChunkSize##' AS size, AVG(CAST(Score AS FLOAT)) AS "average answer score", (SELECT MAX(Score) FROM (SELECT percent AS score FROM Posts AS PU WHERE PostTypeId = 2 ORDER BY Score LIMIT 50) AS t) AS "median answer score", COUNT(*) AS answers FROM Posts WHERE PostTypeId = 2 GROUP BY LENGTH(Body) / '##ChunkSize##' ORDER BY size
### Instruction: what is the average value of protein s in patient 027-144847's body in their first hospital visit? ### Response:
SELECT AVG(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 = '027-144847' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND lab.labname = 'protein s'
### Instruction: New answers to nearly old questions. ### Response:
SELECT pa.Id AS "post_link", pa.Body FROM Posts AS pa, Posts AS pq WHERE pa.ParentId = pq.Id AND pq.CreationDate < '18 Mar 2013' AND pa.CreationDate > '1 Apr 2013' AND DATEDIFF(day, pq.CreationDate, CreationDate) < 30 AND pa.ClosedDate IS NULL AND NOT EXISTS(SELECT 1 FROM PostHistory AS ph WHERE ph.PostId = pa.Id AND ph.PostHistoryTypeId = 12) ORDER BY 2
### Instruction: what was the first time that patient 007-13494 had the minimum value of the systemicsystolic? ### 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 = '007-13494')) AND NOT vitalperiodic.systemicsystolic IS NULL ORDER BY vitalperiodic.systemicsystolic, vitalperiodic.observationtime LIMIT 1
### Instruction: User List: Rep per day. ### Response:
SELECT u.Id AS "user_link", CAST(DATEDIFF(day, u.CreationDate, CURRENT_TIMESTAMP()) AS VARCHAR) + ' days' AS "member_for", u.Reputation AS "rep", ROUND(CAST(u.Reputation AS FLOAT) / (DATEDIFF(day, u.CreationDate, CURRENT_TIMESTAMP())), 1) AS "avg_rep_per_day" FROM Users AS u WHERE u.Reputation > '##MinimumRep##' ORDER BY 'avg_rep_per_day' DESC
### Instruction: give me the number of patients whose diagnoses long title is diabetes with ketoacidosis, type i [juvenile type], not stated as uncontrolled and lab test abnormal status is abnormal? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.long_title = "Diabetes with ketoacidosis, type I [juvenile type], not stated as uncontrolled" AND lab.flag = "abnormal"
### Instruction: was the nicardipine iv prescribed to patient 79348 in 05/this year? ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 79348) AND prescriptions.drug = 'nicardipine iv' AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', prescriptions.startdate) = '05'
### Instruction: when was patient 002-58884 given for the last time a lab test last month? ### 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 = '002-58884')) AND DATETIME(lab.labresulttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: Are there any RESTORA upper-level courses being offered this Spring-Summer ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program_course, semester WHERE course.course_id = course_offering.course_id AND course.department = 'RESTORA' AND program_course.category LIKE '%ULCS%' AND program_course.course_id = course.course_id AND semester.semester = 'Spring-Summer' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: when did patient 007-849 last have wbc x 1000 maximum during this hospital visit? ### 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 = '007-849' AND patient.hospitaldischargetime IS NULL)) AND lab.labname = 'wbc x 1000' ORDER BY lab.labresult DESC, lab.labresulttime DESC LIMIT 1
### Instruction: Is THEORY 590 needed for THEORY 438 ? ### 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 = 'THEORY' AND COURSE_0.number = 590 AND COURSE_1.course_id = course_prerequisite.course_id AND COURSE_1.department = 'THEORY' AND COURSE_1.number = 438
### 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, and list by the names from high to low 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 JOB_ID DESC
### Instruction: Show the number of courses for each course description in a stacked bar chart The x-axis is course description and group by instructor's name, I want to rank y axis in desc order. ### Response:
SELECT CRS_DESCRIPTION, COUNT(CRS_DESCRIPTION) FROM CLASS AS T1 JOIN EMPLOYEE AS T2 ON T1.PROF_NUM = T2.EMP_NUM JOIN COURSE AS T3 ON T1.CRS_CODE = T3.CRS_CODE GROUP BY EMP_FNAME, CRS_DESCRIPTION ORDER BY COUNT(CRS_DESCRIPTION) DESC
### Instruction: when was patient 23070 first tested for mchc a month before? ### Response:
SELECT labevents.charttime FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'mchc') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 23070) AND DATETIME(labevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY labevents.charttime LIMIT 1
### Instruction: how many hours have passed since the last time patient 76332 potassium phosphate was prescribed on the current hospital visit? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', prescriptions.startdate)) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 76332 AND admissions.dischtime IS NULL) AND prescriptions.drug = 'potassium phosphate' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: Post with single bounty by bounty amount. ### Response:
WITH bounties_cte AS (SELECT SUM(v.BountyAmount) AS bntsum, COUNT(v.BountyAmount) AS bntnum, p.Id AS pid, p.ViewCount AS vc FROM Posts AS p JOIN Votes AS v ON v.PostId = p.Id WHERE v.VoteTypeId = 8 GROUP BY p.Id, p.ViewCount) SELECT bntsum AS "total_bounties", COUNT(pid) FROM bounties_cte WHERE bntnum = 1 GROUP BY bntsum ORDER BY bntsum
### 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 job_id and the sum of salary , and group by attribute job_id, show X-axis in desc order. ### 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 JOB_ID DESC
### Instruction: Can I take 611 and 539 as I need to leave for work at 5:00 everyday ? ### Response:
SELECT COUNT(*) = 0 FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE (course.number = 611 OR course.number = 539) AND course_offering.end_time > '17:00:00' AND semester.semester = 'WN' AND semester.year = 2016
### Instruction: In order to fulfill the PreMajor requirement which is the easiest class to take ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, program_course.workload, program_course.workload FROM course, program_course WHERE program_course.category LIKE '%PreMajor%' AND program_course.course_id = course.course_id AND program_course.workload = (SELECT MIN(PROGRAM_COURSEalias1.workload) FROM program_course AS PROGRAM_COURSEalias1 WHERE PROGRAM_COURSEalias1.category LIKE '%PreMajor%')
### Instruction: Can I leave at 5:00 P.M. every day if I take 370 and 489 ? ### Response:
SELECT COUNT(*) = 0 FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE (course.number = 370 OR course.number = 489) AND course_offering.end_time > '17:00:00' AND semester.semester = 'WN' AND semester.year = 2016
### Instruction: count the number of times that patient 70206 had received a alanine aminotransferase (alt) test in 2103? ### Response:
SELECT COUNT(*) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'alanine aminotransferase (alt)') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 70206) AND STRFTIME('%y', labevents.charttime) = '2103'
### Instruction: does respiration of patient 032-21820 be normal on the current hospital visit? ### 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 = '032-21820' AND patient.hospitaldischargetime IS NULL)) AND vitalperiodic.respiration BETWEEN respiration_lower AND respiration_upper AND NOT vitalperiodic.respiration IS NULL
### Instruction: give me patient 74523's yearly maximum pt until 4 years ago. ### Response:
SELECT MAX(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 74523) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'pt') AND DATETIME(labevents.charttime) <= DATETIME(CURRENT_TIME(), '-4 year') GROUP BY STRFTIME('%y', labevents.charttime)
### Instruction: has any famotidine been prescribed to patient 002-17195 in their first hospital encounter? ### 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-17195' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND medication.drugname = 'famotidine'
### Instruction: Longest gaps between answer posting and acceptance. ### Response:
SELECT V.PostId AS "post_link", V.CreationDate AS "accept_date", A.CreationDate AS "question_date", CAST((JULIANDAY(V.CreationDate) - JULIANDAY(A.CreationDate)) * 86400.0 AS INT) AS "difference" FROM Votes AS V INNER JOIN Posts AS A ON (V.PostId = A.Id AND A.PostTypeId = 2) WHERE V.VoteTypeId = 1 ORDER BY 'difference' DESC LIMIT 100
### 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 hire_date bin hire_date by weekday by a bar chart, display sum salary in desc order. ### Response:
SELECT HIRE_DATE, SUM(SALARY) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY SUM(SALARY) DESC
### Instruction: Which upper level electives are offered before noon ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program_course, semester WHERE course_offering.end_time <= '12:00:00' 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 = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: what dose of cyclosporine (neoral) modified was last prescribed to patient 16271 since 80 months ago? ### Response:
SELECT prescriptions.dose_val_rx FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 16271) AND prescriptions.drug = 'cyclosporine (neoral) modified' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-80 month') ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: what was the name of the lab test which patient 012-4131 last received the last month? ### Response:
SELECT lab.labname FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '012-4131')) AND DATETIME(lab.labresulttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: when did patient 8116 get intakes for the first time today? ### Response:
SELECT inputevents_cv.charttime 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 = 8116)) AND DATETIME(inputevents_cv.charttime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-0 day') ORDER BY inputevents_cv.charttime LIMIT 1
### Instruction: what was the first value of sodium of patient 32154 in 01/2104? ### Response:
SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 32154) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'sodium') AND STRFTIME('%y-%m', labevents.charttime) = '2104-01' ORDER BY labevents.charttime LIMIT 1
### Instruction: what is on the first hospital encounter average lactate dehydrogenase, ascites value of patient 88079? ### Response:
SELECT AVG(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 88079 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 = 'lactate dehydrogenase, ascites')
### Instruction: is there any organisms found in patient 65741's last sputum test since 2105? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 65741) AND microbiologyevents.spec_type_desc = 'sputum' AND NOT microbiologyevents.org_name IS NULL AND STRFTIME('%y', microbiologyevents.charttime) >= '2105' ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: Regarding prerequisites , is SOCADMIN 995 mandatory ? ### Response:
SELECT DISTINCT COURSE_1.department, COURSE_1.name, COURSE_1.number 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 = 'SOCADMIN' AND COURSE_0.number = 995 AND COURSE_1.course_id = course_prerequisite.course_id
### Instruction: on the last hospital visit, how many times had patient 010-26737 received a ferrous iron compound? ### Response:
SELECT COUNT(*) FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '010-26737' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND treatment.treatmentname = 'ferrous iron compound'
### Instruction: what was the last time patient 032-25571 had been tested for lab tests in 09/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 = '032-25571')) AND STRFTIME('%y-%m', lab.labresulttime) = '2105-09' ORDER BY lab.labresulttime DESC LIMIT 1
### Instruction: what is the minimum total cost to the hospital that includes albumin until 2 years ago? ### 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 lab.patientunitstayid FROM lab WHERE lab.labname = 'albumin')) AND DATETIME(cost.chargetime) <= DATETIME(CURRENT_TIME(), '-2 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: what was the first time that patient 80119 was prescribed a medication in 01/last year? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 80119) AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', prescriptions.startdate) = '01' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: Average reputation gain by number of questions and answers. ### Response:
SELECT YEAR(Users.CreationDate) AS cYear, MONTH(Users.CreationDate) AS cMonth, SUM(1.0 * Reputation) AS totalReputation, COUNT(Posts.Id) AS totalPosts, SUM(1.0 * Reputation) / COUNT(Posts.Id) AS AvgPointPPost FROM Users JOIN Posts ON Posts.OwnerUserId = Users.Id WHERE Reputation >= '##minRep##' GROUP BY YEAR(Users.CreationDate), MONTH(Users.CreationDate) ORDER BY 1, 2
### Instruction: what is the maximum total cost of the hospital which include fibrinogen since 2102? ### 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 lab.patientunitstayid FROM lab WHERE lab.labname = 'fibrinogen')) AND STRFTIME('%y', cost.chargetime) >= '2102' GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: has patient 015-58787 had an thoracic surgery consultation procedure performed in other hospitals? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.uniquepid = '015-58787' AND patient.hospitalid <> (SELECT DISTINCT patient.hospitalid FROM patient WHERE patient.uniquepid = '015-58787' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'thoracic surgery consultation'
### Instruction: how many days have it been since patient 8888 first received a clopidogrel bisulfate prescription in this hospital encounter? ### Response:
SELECT 1 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', prescriptions.startdate)) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 8888 AND admissions.dischtime IS NULL) AND prescriptions.drug = 'clopidogrel bisulfate' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: Questions which no longer have the given tag (but had it at some point). ### Response:
SELECT DISTINCT Posts.Id AS "post_link", url = 'site://posts/' + CAST(Posts.Id AS TEXT) + '/revisions', Posts.CreationDate, Posts.LastActivityDate FROM PostHistory INNER JOIN Posts ON PostHistory.PostId = Posts.Id WHERE PostHistory.PostHistoryTypeId IN (3, 6, 9) AND PostHistory.Text LIKE '%<##tagName##>%' AND NOT (Posts.Tags LIKE '%<##tagName##>%') ORDER BY Posts.Id
### Instruction: when was patient 002-30780 prescribed a drug for the first time on the last hospital encounter? ### Response:
SELECT medication.drugstarttime FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '002-30780' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) ORDER BY medication.drugstarttime LIMIT 1
### Instruction: what was patient 61751's first measured potassium since 05/2105? ### Response:
SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 61751) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'potassium') AND STRFTIME('%y-%m', labevents.charttime) >= '2105-05' ORDER BY labevents.charttime LIMIT 1
### Instruction: Does anyone teach Professional Communication Strategies besides Prof. Figuero ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, instructor.name FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.name LIKE '%Professional Communication Strategies%' AND NOT instructor.name LIKE '%Figuero%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: when was the first time patient 004-32341 was prescribed a drug in their last hospital visit? ### 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 = '004-32341' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) ORDER BY medication.drugstarttime LIMIT 1
### Instruction: Top Users by Country and Tag. ### Response:
SELECT ROW_NUMBER() OVER (ORDER BY Reputation DESC) AS "#", u.Id AS "user_link", u.Reputation, COUNT(p.Id) 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.Reputation, u.Id ORDER BY Reputation 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, give me the comparison about the sum of salary over the job_id , and group by attribute job_id by a bar chart, and list X in asc order. ### 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 JOB_ID
### Instruction: did patient 006-188114 get a vitamin b12 laboratory test during the first hospital visit? ### 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 = '006-188114' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND lab.labname = 'vitamin b12'
### Instruction: When Prof. Soyoun Kim teaches 232 , will there be classes on Friday ? ### 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.number = 232 AND course_offering.friday = 'N' AND instructor.name LIKE '%Soyoun Kim%'
### Instruction: Is the only person who teaches Engr Prop Soil , Prof. Huffman ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, instructor.name FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.name LIKE '%Engr Prop Soil%' AND NOT instructor.name LIKE '%Huffman%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: when did patient 027-151154 during their current hospital visit have the minimum -eos for the 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 = '027-151154' AND patient.hospitaldischargetime IS NULL)) AND lab.labname = '-eos' ORDER BY lab.labresult, lab.labresulttime 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, return a bar chart about the distribution of hire_date and the sum of salary bin hire_date by weekday, sort Y-axis from high to low order. ### Response:
SELECT HIRE_DATE, SUM(SALARY) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY SUM(SALARY) DESC
### Instruction: Self-answered questions with no other answers. ### Response:
SELECT q.Id AS "post_link", q.CreationDate, q.Score FROM ((SELECT Posts.* FROM Posts WHERE PostTypeId = 1 AND AnswerCount = 1 AND CommunityOwnedDate IS NULL) AS q JOIN (SELECT Posts.* FROM Posts WHERE PostTypeId = 2 AND CommunityOwnedDate IS NULL) AS a ON q.Id = a.ParentId) WHERE q.OwnerUserId = a.OwnerUserId AND q.AnswerCount = 1 AND q.DeletionDate IS NULL AND q.ClosedDate IS NULL ORDER BY CreationDate DESC
### Instruction: Which one of the upper-level FIN classes will be available this Spring-Summer ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program_course, semester WHERE course.course_id = course_offering.course_id AND course.department = 'FIN' AND program_course.category LIKE '%ULCS%' AND program_course.course_id = course.course_id AND semester.semester = 'Spring-Summer' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: what is the maximum total cost to the hospital that includes wbc count in this year? ### Response:
SELECT MAX(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 = 'wbc count')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') GROUP BY cost.hadm_id) AS t1
### Instruction: During the Spring and Summer term , how many 100 -level classes are being offered ? ### Response:
SELECT COUNT(DISTINCT course.course_id, semester.semester) FROM course, course_offering, semester WHERE course.course_id = course_offering.course_id AND course.department = 'department0' AND course.number BETWEEN 100 AND 100 + 100 AND semester.semester IN ('SP', 'SS', 'SU') AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: did there be any organism found in patient 26793's first sterility culture test since 2102? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 26793) AND microbiologyevents.spec_type_desc = 'sterility culture' AND NOT microbiologyevents.org_name IS NULL AND STRFTIME('%y', microbiologyevents.charttime) >= '2102' ORDER BY microbiologyevents.charttime LIMIT 1
### Instruction: give me the the number of patients whose diagnoses long title is acute venous embolism and thrombosis of deep vessels of proximal lower extremity and drug type is base. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.long_title = "Acute venous embolism and thrombosis of deep vessels of proximal lower extremity" AND prescriptions.drug_type = "BASE"
### Instruction: how many hours has passed since the last time on their current hospital visit that patient 42473 was prescribed buprenorphine? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', prescriptions.startdate)) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 42473 AND admissions.dischtime IS NULL) AND prescriptions.drug = 'buprenorphine' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: Accepted answers having question and answer score <0. ### Response:
SELECT q.Id, q.CreationDate, q.Tags, q.Title, q.Body, a.Body, q.Score, a.Score FROM Posts AS q LEFT JOIN Posts AS a ON a.Id = q.AcceptedAnswerId AND a.PostTypeId = 2 WHERE q.PostTypeId = 1 AND a.Score > -0 AND q.Tags LIKE '%<numpy>%' AND NOT a.Body IS NULL AND NOT q.Body IS NULL AND q.CreationDate > '2015-01-01' ORDER BY q.CreationDate
### Instruction: Of the courses being offered this Fall , which are upper-level CHEMBIO classes ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program_course, semester WHERE course.course_id = course_offering.course_id AND course.department = 'CHEMBIO' AND program_course.category LIKE '%ULCS%' AND program_course.course_id = course.course_id AND semester.semester = 'Fall' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: did patient 012-68650 get tested in the prealbumin lab 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 = '012-68650')) AND lab.labname = 'prealbumin' AND DATETIME(lab.labresulttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')
### Instruction: What are all the upper-level CDB classes being offered in the Spring-Summer ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program_course, semester WHERE course.course_id = course_offering.course_id AND course.department = 'CDB' AND program_course.category LIKE '%ULCS%' AND program_course.course_id = course.course_id AND semester.semester = 'Spring-Summer' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: when was patient 14054 last sputum microbiologic test during the last month? ### Response:
SELECT microbiologyevents.charttime FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 14054) AND microbiologyevents.spec_type_desc = 'sputum' AND DATETIME(microbiologyevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: tell me patient 20801's minimum potassium, whole blood value in 10/2102? ### Response:
SELECT MIN(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 20801) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'potassium, whole blood') AND STRFTIME('%y-%m', labevents.charttime) = '2102-10'
### Instruction: Besides Prof. Keppen , is there any other person teaching Analytical Archaeology ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, instructor.name FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.name LIKE '%Analytical Archaeology%' AND NOT instructor.name LIKE '%Keppen%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: what was patient 006-172277's last output on the current intensive care unit 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 = '006-172277') AND patient.unitdischargetime IS NULL) AND intakeoutput.cellpath LIKE '%output%' ORDER BY intakeoutput.intakeoutputtime DESC LIMIT 1
### Instruction: how many hours have passed since the first prescribing of cyanocobalamin in patient 92846 on this hospital visit? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', prescriptions.startdate)) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 92846 AND admissions.dischtime IS NULL) AND prescriptions.drug = 'cyanocobalamin' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: what was patient 027-28154 diagnosed with in 2102 for the last time? ### Response:
SELECT diagnosis.diagnosisname FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '027-28154')) AND STRFTIME('%y', diagnosis.diagnosistime) = '2102' ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: count the number of times patient 012-85821's total co2 test has been taken until 04/2102. ### Response:
SELECT COUNT(*) FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '012-85821')) AND lab.labname = 'total co2' AND STRFTIME('%y-%m', lab.labresulttime) <= '2102-04'
### Instruction: How many courses for each course description? Show me a bar chart, and rank by the y axis in asc. ### Response:
SELECT CRS_DESCRIPTION, COUNT(CRS_DESCRIPTION) FROM CLASS AS T1 JOIN EMPLOYEE AS T2 ON T1.PROF_NUM = T2.EMP_NUM JOIN COURSE AS T3 ON T1.CRS_CODE = T3.CRS_CODE JOIN PROFESSOR AS T4 ON T2.EMP_NUM = T4.EMP_NUM GROUP BY CRS_DESCRIPTION ORDER BY COUNT(CRS_DESCRIPTION)