instruction
stringlengths
53
549
output
stringlengths
30
2.33k
### 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: until 2104 what are the four most commonly ordered medications for patients of age 60 or above? ### 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 >= 60) AND STRFTIME('%y', medication.drugstarttime) <= '2104' GROUP BY medication.drugname) AS t1 WHERE t1.c1 <= 4
### Instruction: Is A History of Modern Psychology only taught by one person , Prof. Hull ? ### 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 '%A History of Modern Psychology%' AND NOT instructor.name LIKE '%Hull%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: has quetiapine fumarate, phenylephrine, or ondansetron been prescribed until 05/2101 for patient 1372? ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 1372) AND prescriptions.drug IN ('quetiapine fumarate', 'phenylephrine', 'ondansetron') AND STRFTIME('%y-%m', prescriptions.startdate) <= '2101-05'
### Instruction: what is the name of the drug patient 017-61209 was first prescribed during the first hospital visit? ### Response:
SELECT medication.drugname FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '017-61209' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) ORDER BY medication.drugstarttime LIMIT 1
### Instruction: until 3 years ago, had patient 029-16737 had a surgery consultation? ### 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 = '029-16737')) AND treatment.treatmentname = 'surgery consultation' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-3 year')
### Instruction: During the Fall or Winter terms , are any 500 -level classes being offered ? ### 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 500 AND 500 + 100 AND semester.semester IN ('FA', 'WN') AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: what are the top four prescription drugs among the patients with age 60 or above until 2103? ### 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 STRFTIME('%y', prescriptions.startdate) <= '2103' GROUP BY prescriptions.drug) AS t1 WHERE t1.c1 <= 4
### Instruction: what was the name of the lab test, which patient 013-17922 first received until 07/2104? ### 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 = '013-17922')) AND STRFTIME('%y-%m', lab.labresulttime) <= '2104-07' ORDER BY lab.labresulttime LIMIT 1
### Instruction: Which classes need BIOSTAT 524 as a prerequisite ? ### 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 = 'BIOSTAT' AND COURSE_0.number = 524 AND COURSE_1.course_id = course_prerequisite.course_id
### Instruction: For Spring and Summer what courses meet the MDE requirement ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, semester.semester FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester INNER JOIN program_course ON program_course.course_id = course_offering.course_id WHERE program_course.category LIKE '%MDE%' AND semester.semester IN ('SP', 'SS', 'SU') AND semester.year = 2016
### Instruction: what is patient 009-16880's last diagnosis on their first hospital visit? ### 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 = '009-16880' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: what exactly was the first drug that patient 10811 was prescribed in 02/last year? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 10811) AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', prescriptions.startdate) = '02' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: What is on offer in the way of hardware courses for Spring and Summer of 2019 ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, semester.semester FROM course INNER JOIN area ON course.course_id = area.course_id INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE area.area LIKE '%hardware%' AND semester.semester IN ('SP', 'SU', 'SS') AND semester.year = 2019
### Instruction: count the number of times that patient 17398 underwent a opn/oth rep mtrl vlv-tis procedure. ### 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 = 'opn/oth rep mtrl vlv-tis') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17398)
### Instruction: what was the total output of patient 59797's jp #2 medial? ### Response:
SELECT SUM(outputevents.value) 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 = 59797)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'jp #2 medial' AND d_items.linksto = 'outputevents')
### Instruction: since 09/2104 has patient 005-87465 had a cortisol lab test? ### 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 = '005-87465')) AND lab.labname = 'cortisol' AND STRFTIME('%y-%m', lab.labresulttime) >= '2104-09'
### Instruction: Server Faults Qns & Ans. ### Response:
SELECT q.Id, q.AcceptedAnswerId, q.Body AS qBody, q.Title AS qTitle, q.Tags AS qTags, q.CommentCount AS qCommentCount, q.Score AS qScore, a.Id, a.Body AS aBody, a.Score AS aScore, a.CommentCount AS aCommentCount FROM Posts AS q INNER JOIN Posts AS a ON (q.AcceptedAnswerId = a.Id) WHERE YEAR(q.CreationDate) > 2013 AND YEAR(q.CreationDate) < 2019
### Instruction: Users with CSS gold badge. ### Response:
SELECT ROW_NUMBER() OVER (ORDER BY u.DisplayName), b.UserId, u.DisplayName AS Name FROM Users AS u, Badges AS b, Badges AS html, Badges AS js WHERE b.Name = 'css' AND b.Class = 1 AND html.Name = 'html' AND html.Class = 1 AND js.Name = 'javascript' AND js.Class = 1 AND u.Id = b.UserId AND u.Id = html.UserId AND u.Id = js.UserId GROUP BY b.Date, b.UserId, u.DisplayName
### Instruction: Count upvotes on top 10 most common tags. ### Response:
SELECT TagName, COUNT(*) AS UpVotes FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.Id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id AND VoteTypeId = 2 WHERE TagName IN (SELECT t.TagName FROM Tags AS t INNER JOIN PostTags AS pt ON pt.TagId = t.Id INNER JOIN Posts AS p ON pt.PostId = p.Id GROUP BY t.TagName ORDER BY COUNT(*) DESC LIMIT 10) GROUP BY TagName
### Instruction: count the number of times that patient 26398 received a laboratory test for vancomycin in a month before. ### Response:
SELECT COUNT(*) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'vancomycin') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 26398) AND DATETIME(labevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### Instruction: since 158 months ago, what was the daily maximum weight of patient 017-70504? ### Response:
SELECT MAX(patient.admissionweight) FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '017-70504') AND NOT patient.admissionweight IS NULL AND DATETIME(patient.unitadmittime) >= DATETIME(CURRENT_TIME(), '-158 month') GROUP BY STRFTIME('%y-%m-%d', patient.unitadmittime)
### Instruction: has patient 030-53416 been treated since 2105 with a ct scan - spine procedure? ### 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 = '030-53416')) AND treatment.treatmentname = 'ct scan - spine' AND STRFTIME('%y', treatment.treatmenttime) >= '2105'
### Instruction: Other than Prof. Jaye Stapleton , name the professors who teach 552 . ### Response:
SELECT DISTINCT instructor.name FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.department = 'EECS' AND course.number = 552 AND NOT instructor.name LIKE '%Jaye Stapleton%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: Are there any courses which require taking RESTORA 746 first ? ### 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 = 'RESTORA' AND COURSE_0.number = 746 AND COURSE_1.course_id = course_prerequisite.course_id
### Instruction: what was the four most commonly taken laboratory tests in 2101 for patients of the age 20s? ### 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 20 AND 29) AND STRFTIME('%y', lab.labresulttime) = '2101' GROUP BY lab.labname) AS t1 WHERE t1.c1 <= 4
### Instruction: what is the daily average amount of rbc, pleural patient 15794 has on the current hospital visit? ### Response:
SELECT AVG(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 15794 AND admissions.dischtime IS NULL) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'rbc, pleural') GROUP BY STRFTIME('%y-%m-%d', labevents.charttime)
### Instruction: Are there any courses in the Fall or Winter that meet the Other requirement ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, semester.semester FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester INNER JOIN program_course ON program_course.course_id = course_offering.course_id WHERE program_course.category LIKE '%Other%' AND semester.semester IN ('FA', 'WN') AND semester.year = 2016
### Instruction: when was the last time that patient 004-86136 has the minimum sodium on their current hospital encounter? ### 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 = '004-86136' AND patient.hospitaldischargetime IS NULL)) AND lab.labname = 'sodium' ORDER BY lab.labresult, lab.labresulttime DESC LIMIT 1
### Instruction: Interesting Recent Unanswered Salesforce Questions From Newbies. ### Response:
SELECT p.Id, p.Title, p.Tags, p.CreationDate FROM Posts AS p INNER JOIN Users AS u ON u.Id = p.OwnerUserId WHERE u.Reputation < 200 AND p.CreationDate > (CURRENT_TIMESTAMP() - 20) AND AnswerCount = 0 AND CommentCount = 0 AND NOT Tags LIKE '%marketing-cloud%' AND NOT Tags LIKE '%lightning%' AND NOT Tags LIKE '%javascript%' AND NOT Tags LIKE '%salesforcedx%' ORDER BY p.CreationDate DESC
### Instruction: Compare number of Questions per week, for 3 given tags, over a specified period. ### Response:
SELECT DATEADD(week, DATEDIFF(week, 0, CreationDate), 0), COUNT(*) FROM PostTags AS pt JOIN Posts AS q ON q.Id = pt.PostId WHERE pt.TagId = 93513 AND q.CreationDate > '2016-07-10' GROUP BY DATEADD(week, DATEDIFF(week, 0, CreationDate), 0) ORDER BY DATEADD(week, DATEDIFF(week, 0, CreationDate), 0)
### Instruction: what is the average hospital cost that would involve a creatinine, pleural lab test in 2104? ### 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 = 'creatinine, pleural')) AND STRFTIME('%y', cost.chargetime) = '2104' GROUP BY cost.hadm_id) AS t1
### Instruction: WHAT WAS THE AMOUNT OF CARBON DIOXIDE EMISSIONS IN 2006 IN THE COUNTRY WHOSE CO2 EMISSIONS (TONS PER PERSON) REACHED 1.4 IN 2OO7? ### Response:
SELECT carbon_dioxide_emissions_per_year__10_6_tons___2006_ FROM table_11251601_2 WHERE carbon_dioxide_emissions_per_year__tons_per_person___2007_ = "1.4"
### Instruction: what is the yearly minimum of patient 006-14121's weight since 05/2105? ### Response:
SELECT MIN(patient.admissionweight) FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-14121') AND NOT patient.admissionweight IS NULL AND STRFTIME('%y-%m', patient.unitadmittime) >= '2105-05' GROUP BY STRFTIME('%y', patient.unitadmittime)
### Instruction: what was the name of the lab test that the previous month patient 73693 received for the last time? ### Response:
SELECT d_labitems.label FROM d_labitems WHERE d_labitems.itemid IN (SELECT labevents.itemid FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 73693) AND DATETIME(labevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY labevents.charttime DESC LIMIT 1)
### Instruction: For Fall 2017 , is there a 1 -credit upper level class ? ### 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.credits = 1 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 = 2017
### Instruction: In the Fall and Winter terms , how many 200 -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 200 AND 200 + 100 AND semester.semester IN ('FA', 'WN') AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: For a CS major , what classes are available this Winter that would count towards that ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program, program_course, semester WHERE program_course.course_id = course.course_id AND program_course.course_id = course.course_id AND program.name LIKE '%CS%' AND program.program_id = program_course.program_id AND semester.semester = 'Winter' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: had sepsis been diagnosed with patient 015-33415 until 2104? ### 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 = '015-33415')) AND diagnosis.diagnosisname = 'sepsis' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2104'
### Instruction: Answers close to the Necromancer badge. All your answers that were posted at least 60 days after the question was posted, with a score of 4 or lower. When any of these reach a score of 5, they should earn you a Necromancer silver badge. ### Response:
SELECT a.Id AS "post_link", a.Score FROM Posts AS q INNER JOIN Posts AS a ON q.Id = a.ParentId WHERE a.PostTypeId = 2 AND a.Score <= 4 AND DATEDIFF(d, q.CreationDate, creationdate) >= 60 ORDER BY a.Score DESC
### Instruction: What's the fed tax that has a total tax greater than 33.2, a minimum sales tax less than 41.01 and in Vancouver, BC? ### Response:
SELECT AVG("Federal excise tax ( CAD\u00a2 / L )") FROM table_48271 WHERE "Total excise tax (CAD\u00a2/L)" > '33.2' AND "Government" = 'vancouver, bc' AND "Minimum tax incl. sales taxes (CAD\u00a2/L)" < '41.01'
### Instruction: what procedure did patient 017-27817 until 2 years ago receive for the last time? ### 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 = '017-27817')) AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-2 year') ORDER BY treatment.treatmenttime DESC LIMIT 1
### Instruction: What are the album titles for albums containing both 'Reggae' and 'Rock' genre tracks? ### Response:
SELECT T1.title FROM album AS T1 JOIN track AS T2 ON T1.albumid = T2.albumid JOIN genre AS T3 ON T2.genreid = T3.genreid WHERE T3.name = 'Reggae' INTERSECT SELECT T1.title FROM album AS T1 JOIN track AS T2 ON T1.albumid = T2.albumid JOIN genre AS T3 ON T2.genreid = T3.genreid WHERE T3.name = 'Rock'
### Instruction: What are the upper-level MUSTHTRE classes being offered this 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 = 'MUSTHTRE' AND program_course.category LIKE '%ULCS%' AND program_course.course_id = course.course_id AND semester.semester = 'Summer' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: did patient 006-10390 underwent a antiemetic - serotonin antagonist in the current hospital visit? ### 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 = '006-10390' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'antiemetic - serotonin antagonist'
### Instruction: what's the first diagnosis patient 006-1629 got on the last hospital encounter? ### 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 = '006-1629' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: How many courses for each course description? Show me a bar chart, list in asc by the X-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 JOIN PROFESSOR AS T4 ON T2.EMP_NUM = T4.EMP_NUM GROUP BY CRS_DESCRIPTION ORDER BY CRS_DESCRIPTION
### Instruction: has vancomycin hcl, phenylephrine, or d5w (excel bag) been prescribed for patient 13806 until 2102? ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 13806) AND prescriptions.drug IN ('vancomycin hcl', 'phenylephrine', 'd5w (excel bag)') AND STRFTIME('%y', prescriptions.startdate) <= '2102'
### Instruction: what's the maximum cost of a hospital with hydromorphone 1 mg/1 ml syr? ### 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 medication.patientunitstayid FROM medication WHERE medication.drugname = 'hydromorphone 1 mg/1 ml syr')) GROUP BY cost.patienthealthsystemstayid) AS t1
### 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 sort names in descending 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 CRS_DESCRIPTION DESC
### Instruction: how many times on the current hospital encounter has patient 004-79017 received enteral perative? ### 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 = '004-79017' AND patient.hospitaldischargetime IS NULL)) AND intakeoutput.cellpath LIKE '%intake%' AND intakeoutput.celllabel = 'enteral perative'
### Instruction: what is the minimum cost in a hospital involving a laboratory test for lithium since 1 year ago? ### Response:
SELECT MIN(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 = 'lithium')) AND DATETIME(cost.chargetime) >= DATETIME(CURRENT_TIME(), '-1 year') GROUP BY cost.hadm_id) AS t1
### Instruction: is there any medication that has been prescribed to patient 016-6009 during the previous month? ### 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 = '016-6009')) AND DATETIME(medication.drugstarttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### Instruction: Bad question days by month. ### Response:
SELECT year_, month_, SUM(CASE WHEN down > 0 THEN 1 ELSE 0 END) AS bad_days FROM (SELECT YEAR(CreationDate) AS year_, MONTH(CreationDate) AS month_, MAX(CASE WHEN Score > 0 THEN 1 ELSE 0 END) AS up, MAX(CASE WHEN Score < 1 THEN 1 ELSE 0 END) AS down FROM Posts WHERE OwnerUserId = '##UserId##' AND PostTypeId = 1 GROUP BY CreationDate) AS question_days GROUP BY year_, month_ ORDER BY year_, month_
### Instruction: What computing infrastructure courses are offered in Spring or Summer 2012 ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, semester.semester FROM course INNER JOIN area ON course.course_id = area.course_id INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE area.area LIKE '%computing infrastructure%' AND semester.semester IN ('SP', 'SU', 'SS') AND semester.year = 2012
### Instruction: Closed Status of All Questions by Reputation. A graph what percentage of questions are closed, grouped by the reputation of the users who asked them. ### Response:
SELECT AVG(ROUND(Reputation, -1)) AS UserReputation, SUM(CASE WHEN ClosedDate IS NULL THEN 1 ELSE 0 END) / CAST(COUNT(Posts.Id) AS FLOAT) AS "PercentOpen" FROM Posts INNER JOIN Users ON (Users.Id = Posts.OwnerUserId) WHERE PostTypeId = 1 AND Reputation < 1000 GROUP BY ROUND(Reputation, -1) ORDER BY UserReputation
### Instruction: show me all the US flights to PITTSBURGH between 1200 and 1600 in the afternoon ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service, city, flight WHERE ((flight.arrival_time <= 1600 AND flight.arrival_time >= 1200) AND city.city_code = airport_service.city_code AND city.city_name = 'PITTSBURGH' AND flight.to_airport = airport_service.airport_code) AND flight.airline_code = 'US'
### Instruction: what is in 02/2103 average ph value of patient 022-87224? ### 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 = '022-87224')) AND lab.labname = 'ph' AND STRFTIME('%y-%m', lab.labresulttime) = '2103-02'
### Instruction: what is patient 006-181433 first diagnosis time of polymyalgia rheumatica? ### Response:
SELECT diagnosis.diagnosistime FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-181433')) AND diagnosis.diagnosisname = 'polymyalgia rheumatica' ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: what was the time of patient 002-52932's first laboratory test when they visited the hospital first 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 = '002-52932' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) ORDER BY lab.labresulttime LIMIT 1
### Instruction: count the number of patients who had a carotid endarterectomy procedure performed two times until 1 year ago. ### Response:
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, COUNT(*) AS c1 FROM patient WHERE patient.patientunitstayid = (SELECT treatment.patientunitstayid FROM treatment WHERE treatment.treatmentname = 'carotid endarterectomy' AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-1 year')) GROUP BY patient.uniquepid) AS t1 WHERE t1.c1 = 2
### Instruction: what number of hours has it been since the last time patient 25733 was prescribed propofol 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 = 25733 AND admissions.dischtime IS NULL) AND prescriptions.drug = 'propofol' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: what were the four most frequently ordered laboratory tests until 2100 for patients aged 50s? ### 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 STRFTIME('%y', lab.labresulttime) <= '2100' GROUP BY lab.labname) AS t1 WHERE t1.c1 <= 4
### Instruction: who are all the co-authors of Srinivasan Iyer ? ### Response:
SELECT DISTINCT AUTHOR_1.authorid FROM author AS AUTHOR_0, author AS AUTHOR_1, writes AS WRITES_0, writes AS WRITES_1 WHERE AUTHOR_0.authorname = 'Srinivasan Iyer' AND WRITES_0.authorid = AUTHOR_0.authorid AND WRITES_1.authorid = AUTHOR_1.authorid AND WRITES_1.paperid = WRITES_0.paperid
### Instruction: what is the daily minimum bicarbonate value for patient 10624 on this hospital encounter? ### Response:
SELECT MIN(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 10624 AND admissions.dischtime IS NULL) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'bicarbonate') GROUP BY STRFTIME('%y-%m-%d', labevents.charttime)
### Instruction: Which MODGREEK classes are considered upper-level this Spring ? ### 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 = 'MODGREEK' 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 = 2016
### Instruction: Find the transaction type descriptions and dates if the share count is smaller than 10, group by transaction type, count the date of transaction, and bin the date into the weekday interval Show the result with a grouping line chart, and order by the x axis in descending. ### Response:
SELECT T2.date_of_transaction, COUNT(T2.date_of_transaction) FROM Ref_Transaction_Types AS T1 JOIN Transactions AS T2 ON T1.transaction_type_code = T2.transaction_type_code WHERE T2.share_count < 10 GROUP BY transaction_type_description ORDER BY date_of_transaction DESC
### Instruction: the number of patients who had a colonoscopy procedure in 2103. ### 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 = 'colonoscopy') AND STRFTIME('%y', procedures_icd.charttime) = '2103')
### Instruction: My median and average answer score at given date. Reports median and average answer score. The MedianAnswerScore2 is more precise version of median. ### Response:
SELECT COUNT(Posts.Id) AS Answers, (SELECT MAX(Score) FROM (SELECT percent AS Score FROM Posts AS PU WHERE PostTypeId = 2 AND CommunityOwnedDate IS NULL AND PU.OwnerUserId = '##UserId##' ORDER BY Score LIMIT 50) AS t) AS MedianAnswerScore FROM Posts WHERE PostTypeId = 2 AND CommunityOwnedDate IS NULL AND OwnerUserId = '##UserId##'
### Instruction: has patient 006-140729 been prescribed glucagon in 2105. ### 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 = '006-140729')) AND medication.drugname = 'glucagon' AND STRFTIME('%y', medication.drugstarttime) = '2105'
### Instruction: give me the total amount of patient 594's input on 05/10/2105? ### 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 = 594)) AND STRFTIME('%y-%m-%d', inputevents_cv.charttime) = '2105-05-10'
### Instruction: how many times did patient 016-30273 get -lymphs tested until 22 months ago? ### 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 = '016-30273')) AND lab.labname = '-lymphs' AND DATETIME(lab.labresulttime) <= DATETIME(CURRENT_TIME(), '-22 month')
### Instruction: Weaksauce Rep Per Character. This is dirty because it doesn't strip HTML tags ### Response:
SELECT PostID = p.Id, u.DisplayName, AnswerRep = p.Score * 10, AnswerLength = (LENGTH(p.Body)), RepPerChar = CAST((p.Score * 10) AS FLOAT(23, 13)) / CAST((LENGTH(p.Body)) AS FLOAT(23, 13)) FROM Users AS u JOIN Posts AS p ON u.Id = p.OwnerUserId WHERE p.PostTypeId = 2 ORDER BY u.DisplayName DESC
### Instruction: how many patients are with married marital status diagnosed for subarachnoid hemorrhage following injury without mention of open intracranial wound with loss of consciousness of unspecified duration? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.marital_status = "MARRIED" AND diagnoses.long_title = "Subarachnoid hemorrhage following injury without mention of open intracranial wound, with loss of consciousness of unspecified duration"
### Instruction: Comments from one user under question from another user. ### Response:
SELECT CONCAT('https://stats.meta.stackexchange.com/questions/', Posts.ParentId, '/', MyComments.PostId, '#comment', MyComments.Id, '_', MyComments.PostId) AS Link, MyComments.*, Posts.ParentId FROM (SELECT * FROM Comments WHERE UserId = '805') AS MyComments, Posts AS Posts WHERE Posts.Id = MyComments.PostId AND Posts.OwnerUserId = '58675' AND Posts.PostTypeId = 1
### Instruction: Questions with one tag on [pets.se]. Find all the questions on [pets.se] that have exactly one tag, with the premise that they need more to classify (at least) pet type and the problem. ### Response:
WITH singletons AS (SELECT PostId FROM PostTags GROUP BY PostId HAVING COUNT(PostTags.TagId) = 1) SELECT Id, Id AS "post_link", Tags FROM Posts INNER JOIN singletons ON singletons.PostId = Posts.Id WHERE Posts.PostTypeId = 1 AND Posts.ClosedDate IS NULL ORDER BY Posts.Id
### Instruction: did 5% dextrose, ranitidine, or albumin 25% (12.5gm) have been ordered for patient 17462 during this hospital visit. ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17462 AND admissions.dischtime IS NULL) AND prescriptions.drug IN ('5% dextrose', 'ranitidine', 'albumin 25% (12.5gm)')
### Instruction: Do any professors besides Pinella teach The Writing of Poetry ? ### 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 '%The Writing of Poetry%' AND NOT instructor.name LIKE '%Pinella%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: what was the name of the procedure, which patient 015-33415 was first received until 2104? ### 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 = '015-33415')) AND STRFTIME('%y', treatment.treatmenttime) <= '2104' ORDER BY treatment.treatmenttime LIMIT 1
### Instruction: what is patient 52456's minimum value of lipase last month? ### Response:
SELECT MIN(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 52456) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'lipase') AND DATETIME(labevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### Instruction: What is the Pine Rivers total population after 1947 with a Redcliffe population smaller than 68,877, a total population greater than 50,785, and a Caboolture population greater than 12,207? ### Response:
SELECT COUNT("(Pine Rivers)") FROM table_71057 WHERE "Year" > '1947' AND "(Redcliffe)" < '68,877' AND "Population (Total)" > '50,785' AND "(Caboolture)" > '12,207'
### Instruction: Got most down to non-CW answers. ### Response:
SELECT DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS Rank, Posts.OwnerUserId AS "user_link", Posts.OwnerUserId AS UserId, COUNT(*) AS Count FROM Posts, Votes WHERE Posts.Id = Votes.PostId AND Votes.VoteTypeId = 3 AND Posts.PostTypeId = 2 AND Posts.CommunityOwnedDate IS NULL AND Posts.OwnerUserId > 0 GROUP BY Posts.OwnerUserId ORDER BY Count DESC, UserId LIMIT 100
### Instruction: show me the flights from IAD to SAN FRANCISCO leaving after 1800 ### Response:
SELECT DISTINCT flight.flight_id FROM airport, airport_service, city, flight WHERE (city.city_code = airport_service.city_code AND city.city_name = 'SAN FRANCISCO' AND flight.departure_time > 1800 AND flight.to_airport = airport_service.airport_code) AND airport.airport_code = 'IAD' AND flight.from_airport = airport.airport_code
### Instruction: List the medicine name and trade name which can both interact as 'inhibitor' and 'activitor' with enzymes. ### Response:
SELECT T1.name, T1.trade_name FROM medicine AS T1 JOIN medicine_enzyme_interaction AS T2 ON T2.medicine_id = T1.id WHERE interaction_type = 'inhibitor' INTERSECT SELECT T1.name, T1.trade_name FROM medicine AS T1 JOIN medicine_enzyme_interaction AS T2 ON T2.medicine_id = T1.id WHERE interaction_type = 'activitor'
### Instruction: had patient 006-36108 during a month before been allergic to any substance? ### Response:
SELECT COUNT(*) > 0 FROM allergy WHERE allergy.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-36108')) AND DATETIME(allergy.allergytime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### Instruction: Name the professors who teach 560 other than Prof. Joseph Doman . ### Response:
SELECT DISTINCT instructor.name FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.department = 'EECS' AND course.number = 560 AND NOT instructor.name LIKE '%Joseph Doman%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: What class is the easiest that I can take to fulfill the MDE requirement ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, program_course.workload, program_course.workload FROM course, program_course WHERE program_course.category LIKE '%MDE%' 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 '%MDE%')
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, draw a bar chart about the distribution of hire_date and the average of department_id bin hire_date by time, rank by the the average of department id from high to low. ### Response:
SELECT HIRE_DATE, AVG(DEPARTMENT_ID) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY AVG(DEPARTMENT_ID) DESC
### Instruction: what were the three most frequently taken lab tests in 2104 for patients 50s? ### 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 STRFTIME('%y', lab.labresulttime) = '2104' GROUP BY lab.labname) AS t1 WHERE t1.c1 <= 3
### Instruction: has there been a microbiology test conducted since 75 months ago on patient 031-19622? ### 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 = '031-19622')) AND DATETIME(microlab.culturetakentime) >= DATETIME(CURRENT_TIME(), '-75 month')
### Instruction: Do good questions have question marks?. ### Response:
SELECT COUNT(*) AS "count", SUM(Score) AS "sum", SUM(FavoriteCount) AS FavoriteCount, CAST(SUM(Score) AS FLOAT) / COUNT(*) AS AverageScore, CAST(SUM(FavoriteCount) AS FLOAT) / COUNT(*) AS AverageFavoriteCount, CASE WHEN Body LIKE '%?%' OR Title LIKE '%?%' THEN 1 ELSE 0 END AS QuestionMark FROM Posts WHERE PostTypeId = 1 GROUP BY CASE WHEN Body LIKE '%?%' OR Title LIKE '%?%' THEN 1 ELSE 0 END
### Instruction: what was the name of the allergy that was patient 004-18459 had since 02/2105? ### Response:
SELECT allergy.allergyname FROM allergy WHERE allergy.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '004-18459')) AND STRFTIME('%y-%m', allergy.allergytime) >= '2105-02'
### Instruction: how many hours have passed since first hydroxyzine was prescribed to patient 14671 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 = 14671 AND admissions.dischtime IS NULL) AND prescriptions.drug = 'hydroxyzine' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: what was the last anion gap value when they visited the hospital first time for patient 69819? ### Response:
SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 69819 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'anion gap') ORDER BY labevents.charttime DESC LIMIT 1
### Instruction: Questions answered by users with > X reputation. ### Response:
SELECT Q.Id, SUM(IIF(U.Reputation >= @Reputation, 1, 0)) AS HighRep, SUM(IIF(U.Reputation < @Reputation, 1, 0)) AS LowRep FROM Posts AS Q LEFT JOIN (Posts AS A INNER JOIN Users AS U ON A.OwnerUserId = U.Id) ON A.ParentId = Q.Id WHERE Q.ParentId IS NULL AND Q.CreationDate > DATEADD(m, -1, GETDATE()) AND NOT A.Id IS NULL GROUP BY Q.Id
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, give me the comparison about the sum of employee_id over the hire_date bin hire_date by time by a bar chart, display total number from high to low order. ### Response:
SELECT HIRE_DATE, SUM(EMPLOYEE_ID) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY SUM(EMPLOYEE_ID) DESC
### Instruction: count the number of times patient 027-28154 has received a calcium laboratory test until 3 years ago. ### 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 = '027-28154')) AND lab.labname = 'calcium' AND DATETIME(lab.labresulttime) <= DATETIME(CURRENT_TIME(), '-3 year')
### Instruction: Tags associated with 'homework' tag ordered by question count. This query can help with the 'homework' tag cleanup. Each tag listed in this result is associated with the given number of 'homework' questions. ### Response:
SELECT COUNT(*), at.TagName FROM PostTags AS a JOIN PostTags AS b ON (a.PostId = b.PostId) JOIN Tags AS at ON (a.TagId = at.Id) JOIN Tags AS bt ON (b.TagId = bt.Id) WHERE bt.TagName = 'homework' AND at.TagName != 'homework' GROUP BY at.TagName ORDER BY 1 DESC
### Instruction: Percent of questions with a given tag per day. ### Response:
WITH QuesTagInfo(quesId, quesCreationDate, quesHasTag) AS (SELECT Id AS quesId, DATE(CreationDate) AS quesCreationDate, CASE WHEN (Tags LIKE ('%<##TagName##>%')) THEN 1 ELSE 0 END AS quesHasTag FROM Posts WHERE PostTypeId = 1) SELECT quesCreationDate, COUNT(*) AS "total_questions", SUM(quesHasTag) AS "has_tag" FROM QuesTagInfo GROUP BY quesCreationDate ORDER BY quesCreationDate
### 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 trend about employee_id over hire_date , and could you order HIRE_DATE in descending order please? ### Response:
SELECT HIRE_DATE, EMPLOYEE_ID FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY HIRE_DATE DESC