instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: among the patients of age 40s in 2101, what are the top four most frequent lab tests? ### Response:
SELECT d_labitems.label FROM d_labitems WHERE d_labitems.itemid IN (SELECT t1.itemid FROM (SELECT labevents.itemid, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.age BETWEEN 40 AND 49) AND STRFTIME('%y', labevents.charttime) = '2101' GROUP BY labevents.itemid) AS t1 WHERE t1.c1 <= 4)
### Instruction: For CLCIV 327 , who is teaching next semester ? ### Response:
SELECT DISTINCT instructor.name FROM instructor INNER JOIN offering_instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN course_offering ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN course ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE course.department = 'CLCIV' AND course.number = 327 AND semester.semester = 'FA' AND semester.year = 2016
### Instruction: What is Dr. Eran Pichersky is class schedule next semester ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND instructor.name LIKE '%Eran Pichersky%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: Find the name of branches where have some members whose hometown is in Louisville, Kentucky and some in Hiram, Georgia. ### Response:
SELECT T2.name FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id JOIN member AS T3 ON T1.member_id = T3.member_id WHERE T3.hometown = 'Louisville , Kentucky' INTERSECT SELECT T2.name FROM membership_register_branch AS T1 JOIN branch AS T2 ON T1.branch_id = T2.branch_id JOIN member AS T3 ON T1.member_id = T3.member_id WHERE T3.hometown = 'Hiram , Georgia'
### Instruction: did any organisms be found in the first peripheral blood lymphocytes microbiology test done on patient 10624 in 12/2105? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 10624) AND microbiologyevents.spec_type_desc = 'peripheral blood lymphocytes' AND NOT microbiologyevents.org_name IS NULL AND STRFTIME('%y-%m', microbiologyevents.charttime) = '2105-12' ORDER BY microbiologyevents.charttime LIMIT 1
### Instruction: Does 628 have any software course prerequisites ? ### Response:
SELECT DISTINCT COURSE_0.department, COURSE_0.name, COURSE_0.number FROM course AS COURSE_0 INNER JOIN course_prerequisite ON COURSE_0.course_id = course_prerequisite.pre_course_id INNER JOIN course AS COURSE_1 ON COURSE_1.course_id = course_prerequisite.course_id INNER JOIN area ON COURSE_0.course_id = area.course_id WHERE area.area LIKE '%software%' AND COURSE_1.department = 'department0' AND COURSE_1.number = 628
### Instruction: During next semester , what classes will Dr. Jonathan Bulkley be teaching ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND instructor.name LIKE '%Jonathan Bulkley%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: Trend of users last access date who are eligible for the election. ### Response:
SELECT DATEFROMPARTS(TIME_TO_STR(UT.LastAccessDate, '%Y'), TIME_TO_STR(UT.LastAccessDate, '%m'), TIME_TO_STR(UT.LastAccessDate, '%d')) AS "last_accessed", COUNT(UT.Id) AS "eligible" FROM Users AS UT WHERE UT.Reputation >= 150 GROUP BY DATEFROMPARTS(TIME_TO_STR(UT.LastAccessDate, '%Y'), TIME_TO_STR(UT.LastAccessDate, '%m'), TIME_TO_STR(UT.LastAccessDate, '%d')) ORDER BY 'last_accessed'
### Instruction: what was patient 16572's intake for the last time until 1926 days ago? ### Response:
SELECT d_items.label FROM d_items WHERE d_items.itemid IN (SELECT inputevents_cv.itemid 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 = 16572)) AND DATETIME(inputevents_cv.charttime) <= DATETIME(CURRENT_TIME(), '-1926 day') ORDER BY inputevents_cv.charttime DESC LIMIT 1)
### Instruction: Open questions by users with rep>1000 from the past year, with link to post. ### Response:
SELECT Users.Id AS "user_link", Posts.Title AS "posts_link", 'http://english.stackexchange.com/questions/' + CAST(Posts.Id AS TEXT), Posts.LastEditDate, Posts.CreationDate, Posts.ClosedDate, Posts.AcceptedAnswerId FROM Users INNER JOIN Posts ON Users.Id = OwnerUserId WHERE Reputation >= 1000 AND Title != '' AND Posts.CreationDate > CURRENT_TIMESTAMP() - 365 AND ClosedDate IS NULL AND Posts.AcceptedAnswerId IS NULL ORDER BY 'lasteditdate' DESC
### Instruction: tell me the total of patient 7524's inputs on 02/08/last year? ### 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 = 7524)) AND DATETIME(inputevents_cv.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m-%d', inputevents_cv.charttime) = '02-08'
### Instruction: All Answers with some attributes. ### Response:
SELECT a.Score, q.Id, q.OwnerUserId, a.Score, q.CreationDate, q.Tags, a.Score, a.Score, a.Id, a.OwnerUserId, a.Score, a.CreationDate FROM Posts AS a JOIN Posts AS q ON a.ParentId = q.Id WHERE q.CreationDate >= '2013-01-01 00:00:00' AND a.CreationDate >= '2013-04-01 00:00:00' AND a.CreationDate < '2013-07-01 00:00:00'
### Instruction: what is the name of the intake that patient 30044 first had until 1547 days ago? ### Response:
SELECT d_items.label FROM d_items WHERE d_items.itemid IN (SELECT inputevents_cv.itemid 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 = 30044)) AND DATETIME(inputevents_cv.charttime) <= DATETIME(CURRENT_TIME(), '-1547 day') ORDER BY inputevents_cv.charttime LIMIT 1)
### Instruction: count the number of times patient 028-40370 had been prescribed dext 5% in water 1000 ml lvp since 2105. ### 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 = '028-40370')) AND medication.drugname = 'dext 5% in water 1000 ml lvp' AND STRFTIME('%y', medication.drugstarttime) >= '2105'
### Instruction: did patient 031-16123 have the results of the microbiology test of the urine, voided specimen last month? ### 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 = '031-16123')) AND microlab.culturesite = 'urine, voided specimen' AND DATETIME(microlab.culturetakentime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### Instruction: what was the name of the drug that's been prescribed to patient 006-47576 two times on the current hospital encounter? ### Response:
SELECT t1.drugname FROM (SELECT medication.drugname, COUNT(medication.drugstarttime) AS c1 FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-47576' AND patient.hospitaldischargetime IS NULL)) GROUP BY medication.drugname) AS t1 WHERE t1.c1 = 2
### Instruction: Who is the teacher of Antebellum Society and the Civil War in this semester ? ### Response:
SELECT DISTINCT instructor.name FROM instructor INNER JOIN offering_instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN course_offering ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN course ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE course.name LIKE '%Antebellum Society and the Civil War%' AND semester.semester = 'WN' AND semester.year = 2016
### Instruction: No Thanks III: The Revenge. ### Response:
SELECT Id AS "post_link", Body FROM Posts WHERE LOWER(Body) LIKE '%regards%' OR LOWER(Body) LIKE '%greetings%' OR LOWER(Body) LIKE '%tanks in%' OR LOWER(Body) LIKE '%i need%help%' OR LOWER(Body) LIKE '%i need%halp%' OR LOWER(Body) LIKE '%hi %' OR LOWER(Body) LIKE 'guys%' OR LOWER(Body) LIKE '%hello%' OR LOWER(Body) LIKE '%good morning%' OR LOWER(Body) LIKE '%good day%' OR LOWER(Body) LIKE '%good afternoon%' LIMIT 1000
### Instruction: Overall site activity per hour. ### Response:
SELECT h.hours AS "hour", COUNT(postsCounter) AS "posts" FROM (SELECT TIME_TO_STR(CreationDate, '%h') AS active, 1 AS counter, 1 AS postsCounter, NULL AS commentsCounter, NULL AS editsCounter, NULL AS suggestedCounter FROM Votes WHERE VoteTypeId = 1 AND TIME_TO_STR(CreationDate, '%Y') >= 2013) AS a RIGHT JOIN (SELECT DISTINCT TIME_TO_STR(CreationDate, '%h') AS hours FROM Votes WHERE VoteTypeId = 1) AS h ON a.active = h.hours GROUP BY h.hours ORDER BY h.hours
### Instruction: what is the yearly average of the weight of patient 17237? ### Response:
SELECT AVG(chartevents.valuenum) FROM chartevents WHERE chartevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17237)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'admit wt' AND d_items.linksto = 'chartevents') GROUP BY STRFTIME('%y', chartevents.charttime)
### Instruction: Top users in Sri Lanka in Scala. ### Response:
SELECT ROW_NUMBER() OVER (ORDER BY U.Reputation DESC, U.Age) AS "#", U.Id AS "user_link", U.Age, U.Location, U.Reputation, U.UpVotes, U.DownVotes FROM Users AS U WHERE U.Id IN (SELECT DISTINCT U.Id FROM Users AS U INNER JOIN Posts AS P ON U.Id = P.OwnerUserId INNER JOIN PostTags AS PT ON PT.PostId = P.Id INNER JOIN Tags AS T ON T.Id = PT.TagId WHERE LOWER(U.Location) LIKE '%sri lanka%' AND LOWER(T.TagName) LIKE 'scala%')
### Instruction: what was the last time that patient 004-64091 was diagnosed with congestive heart failure since 2102? ### 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 = '004-64091')) AND diagnosis.diagnosisname = 'congestive heart failure' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2102' ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: what is the drug that patient 009-9534 was prescribed for the last time via nebulization route in 02/2102? ### 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 = '009-9534')) AND medication.routeadmin = 'nebulization' AND STRFTIME('%y-%m', medication.drugstarttime) = '2102-02' ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: Most common tags with missing wiki and excerpt. Lists the most commonly used tags with empty/missing tag wikis (wiki AND excerpt). ### Response:
SELECT Count, ('site://tags/' + TagName + '|' + TagName) AS TagName, ExcerptPostId AS "post_link", WikiPostId AS "post_link" FROM Tags AS t LEFT JOIN Posts AS pe ON pe.Id = t.ExcerptPostId LEFT JOIN Posts AS pw ON pw.Id = t.WikiPostId WHERE ExcerptPostId IS NULL AND WikiPostId IS NULL OR LENGTH(pe.Body) = 0 OR LENGTH(pw.Body) = 0 ORDER BY Count DESC
### Instruction: how many times did patient 027-122814 make the stool until 03/30/2104? ### 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 = '027-122814')) AND intakeoutput.cellpath LIKE '%output%' AND intakeoutput.celllabel = 'stool' AND STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime) <= '2104-03-30'
### Instruction: JSP thread volume, page views, unique OPs by month. ### Response:
SELECT COUNT(*) AS Volume, SUM(ViewCount) AS PageViews, COUNT(DISTINCT OwnerUserId) AS UniqueOPs, TIME_TO_STR(P.CreationDate, '%Y') AS "year", TIME_TO_STR(P.CreationDate, '%m') AS Month FROM Posts AS P WHERE (Tags LIKE '%<jsp%') AND PostTypeId = 1 AND CommunityOwnedDate IS NULL AND ClosedDate IS NULL GROUP BY TIME_TO_STR(P.CreationDate, '%YEAR'), TIME_TO_STR(P.CreationDate, '%-mONT%-H') ORDER BY 'year', Month
### Instruction: has there been any organism found until 2103 during the first other microbiology test of patient 031-22988? ### 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-22988')) AND microlab.culturesite = 'other' AND STRFTIME('%y', microlab.culturetakentime) <= '2103' ORDER BY microlab.culturetakentime LIMIT 1
### Instruction: tell me the minimum cost of a hospital that involved pancreatitis - relapsing last year? ### 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 diagnosis.patientunitstayid FROM diagnosis WHERE diagnosis.diagnosisname = 'pancreatitis - relapsing')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: how much is the minimum total hospital cost that includes s/p surgical repair of fracture - spine since 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 diagnosis.patientunitstayid FROM diagnosis WHERE diagnosis.diagnosisname = 's/p surgical repair of fracture - spine')) AND STRFTIME('%y', cost.chargetime) >= '2104' GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: is since 1 year ago patient 42473 diagnosed with hx of past noncompliance? ### Response:
SELECT COUNT(*) > 0 FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'hx of past noncompliance') AND diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 42473) AND DATETIME(diagnoses_icd.charttime) >= DATETIME(CURRENT_TIME(), '-1 year')
### Instruction: what is the number of times that patient 76327 had had foley today? ### Response:
SELECT COUNT(*) 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 = 76327)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'foley' AND d_items.linksto = 'outputevents') AND DATETIME(outputevents.charttime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-0 day')
### Instruction: when did patient 030-47098 first receive an valve replacement >= 7 days diagnosis until 2103? ### 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 = '030-47098')) AND diagnosis.diagnosisname = 'valve replacement >= 7 days' AND STRFTIME('%y', diagnosis.diagnosistime) <= '2103' ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: What are the 100 -level courses in Fall and Winter , if there are any ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, semester.semester FROM course, course_offering, semester WHERE ((semester.semester = 'FA' AND semester.year = 2016) OR (semester.semester = 'WN' AND semester.year = 2017)) AND course.course_id = course_offering.course_id AND course.department = 'department0' AND course.number BETWEEN 100 AND 100 + 100 AND semester.semester_id = course_offering.semester
### Instruction: what's the first time patient 003-17096 had a maximum -lymphs the 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 = '003-17096')) AND lab.labname = '-lymphs' AND DATETIME(lab.labresulttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY lab.labresult DESC, lab.labresulttime LIMIT 1
### Instruction: tell me the total dose of prismasate (b22 k4) prescribed to patient 3403 in 07/this year? ### Response:
SELECT SUM(prescriptions.dose_val_rx) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 3403) AND prescriptions.drug = 'prismasate (b22 k4)' AND DATETIME(prescriptions.startdate, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', prescriptions.startdate) = '07'
### Instruction: what was patient 57023's last blood culture ( myco/f lytic bottle)'s microbiology test time in the last month? ### Response:
SELECT microbiologyevents.charttime FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 57023) AND microbiologyevents.spec_type_desc = 'blood culture ( myco/f lytic bottle)' AND DATETIME(microbiologyevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: when was patient 010-16572's systemicdiastolic measured for the first time until 1 day ago? ### 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-16572')) AND NOT vitalperiodic.systemicdiastolic IS NULL AND DATETIME(vitalperiodic.observationtime) <= DATETIME(CURRENT_TIME(), '-1 day') ORDER BY vitalperiodic.observationtime LIMIT 1
### Instruction: what was the 'output' patient 027-22704 got until 1344 days ago for the last time? ### 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 = '027-22704')) AND intakeoutput.cellpath LIKE '%output%' AND DATETIME(intakeoutput.intakeoutputtime) <= DATETIME(CURRENT_TIME(), '-1344 day') ORDER BY intakeoutput.intakeoutputtime DESC LIMIT 1
### Instruction: Question by user A answered by user B. ### Response:
SELECT q.Id AS "post_link", q.OwnerUserId AS "user_link", q.Score AS "Q Score", a.Id AS "post_link", a.OwnerUserId AS "user_link", a.Score AS "A Score", CASE WHEN q.AcceptedAnswerId = a.Id THEN 1 ELSE 0 END AS "Accepted?" FROM Posts AS q INNER JOIN Posts AS a ON a.ParentId = q.Id WHERE q.PostTypeId = 1 AND a.PostTypeId = 2 AND q.OwnerUserId = '##questUserID##' AND a.OwnerUserId = '##answerUserId##' ORDER BY q.CreationDate
### Instruction: when was the first time that fentanyl (pf) 50 mcg/1 ml 2 ml inj was prescribed to patient 004-32341? ### 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 medication.drugname = 'fentanyl (pf) 50 mcg/1 ml 2 ml inj' ORDER BY medication.drugstarttime LIMIT 1
### Instruction: Users by badges by badge category?. ### Response:
WITH linqbadges AS (SELECT RANK() OVER (PARTITION BY b.UserId ORDER BY b.Date) AS rn, b.UserId, b.Date, b.Name FROM Badges AS b WHERE b.Name = 'Necromancer') SELECT u.DisplayName, linqbadges.Date AS date_earned, CASE rn WHEN 1 THEN 'bronze linq' WHEN 2 THEN 'silver linq' WHEN 3 THEN 'gold linq' END AS badge, linqbadges.Name AS name FROM linqbadges INNER JOIN Users AS u ON linqbadges.UserId = u.Id ORDER BY DisplayName, date_earned
### Instruction: Users with lowest reputation who have a gold badge. ### Response:
WITH badges_cte AS (SELECT UserId AS uid, SUM(CASE WHEN Class = 1 THEN 1 ELSE 0 END) AS gold, SUM(CASE WHEN Class = 2 THEN 1 ELSE 0 END) AS silver, SUM(CASE WHEN Class = 3 THEN 1 ELSE 0 END) AS bronze, COUNT(Id) AS total FROM Badges GROUP BY UserId) SELECT u.Id AS "user_link", u.Reputation, b.gold, b.silver, b.bronze FROM badges_cte AS b INNER JOIN Users AS u ON b.uid = u.Id WHERE (gold >= 1) ORDER BY Reputation LIMIT 100
### Instruction: Math posts with votes before they were created. ### Response:
SELECT pv.age AS "post_age", pv.VoteId AS "vote_id", pv.VoteTypeId AS "vote_type", pv.UserId AS "vote_user", pv.UserId AS "user_link", pv.Id AS "post_link" FROM (SELECT DATEDIFF(day, CAST(p.CreationDate AS DATE), CreationDate) AS age, p.Id, v.Id AS VoteId, v.VoteTypeId, v.UserId FROM Posts AS p LEFT JOIN Votes AS v ON p.Id = v.PostId) AS pv WHERE pv.age < 0 ORDER BY pv.age
### Instruction: what is the maximum number of patients diagnosed with sprain of neck monthly until 2104? ### Response:
SELECT MAX(t1.c1) FROM (SELECT COUNT(DISTINCT diagnoses_icd.hadm_id) AS c1 FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'sprain of neck') AND STRFTIME('%y', diagnoses_icd.charttime) <= '2104' GROUP BY STRFTIME('%y-%m', diagnoses_icd.charttime)) AS t1
### Instruction: get me the top four most common treatments during this year? ### Response:
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT t1.icd9_code FROM (SELECT procedures_icd.icd9_code, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM procedures_icd WHERE DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') GROUP BY procedures_icd.icd9_code) AS t1 WHERE t1.c1 <= 4)
### Instruction: Next time when EECS 181 will be offered ? ### Response:
SELECT DISTINCT semester.semester, semester.year FROM course, course_offering, semester WHERE course.course_id = course_offering.course_id AND course.department = 'EECS' AND course.number = 181 AND course_offering.semester = semester.semester_id AND semester.semester_id > (SELECT SEMESTERalias1.semester_id FROM semester AS SEMESTERalias1 WHERE SEMESTERalias1.semester = 'WN' AND SEMESTERalias1.year = 2016) ORDER BY semester.semester_id LIMIT 1
### Instruction: how many patients are diagnosed a year before with chest swelling/mass/lump? ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT diagnoses_icd.hadm_id FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'chest swelling/mass/lump') AND DATETIME(diagnoses_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year'))
### Instruction: Tags with most closed question (percentage). ### Response:
WITH myTags AS (SELECT t.TagName AS Name, COUNT(pt.TagId) AS Total, (SELECT COUNT(p.Id) FROM Posts AS p INNER JOIN PostTags AS pt2 ON pt2.TagId = t.Id WHERE p.Id = pt2.PostId AND NOT p.ClosedDate IS NULL) AS ClosedTotal FROM Tags AS t INNER JOIN PostTags AS pt ON pt.TagId = t.Id GROUP BY t.TagName, t.Id) SELECT t.Name AS TagName, t.Total AS Total, t.ClosedTotal AS Closed, (100. * t.closedTotal / t.Total) AS "%" FROM myTags AS t ORDER BY '%' DESC
### Instruction: tell me the time when patient 027-136480 measured respiration for the last time since 238 days ago? ### 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 = '027-136480')) AND NOT vitalperiodic.respiration IS NULL AND DATETIME(vitalperiodic.observationtime) >= DATETIME(CURRENT_TIME(), '-238 day') ORDER BY vitalperiodic.observationtime DESC LIMIT 1
### Instruction: Dr. Kristen Verhey is instructing which classes next semester ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND instructor.name LIKE '%Kristen Verhey%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: tell me the procedure that patient 15760 last had during the previous year? ### Response:
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT procedures_icd.icd9_code FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 15760) AND DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') ORDER BY procedures_icd.charttime DESC LIMIT 1)
### Instruction: Average Scores for Closed Questions. ### Response:
SELECT TIME_TO_STR(CreationDate, '%Y') * 12 + TIME_TO_STR(CreationDate, '%m'), AVG(Score) FROM Posts GROUP BY TIME_TO_STR(CreationDate, '%Y') * 12 + TIME_TO_STR(CreationDate, '%m') HAVING TIME_TO_STR(CreationDate, '%Y') * 12 + TIME_TO_STR(CreationDate, '%m') > 24105 ORDER BY TIME_TO_STR(CreationDate, '%Y') * 12 + TIME_TO_STR(CreationDate, '%m')
### Instruction: Top Users By Tag and Location. ### Response:
SELECT ROW_NUMBER() OVER (ORDER BY SUM(p.Score) DESC) AS "#", p.OwnerUserId AS "user_link", MAX(u.Reputation) AS "total_reputation", SUM(p.Score) AS "tag_repuation" FROM Users AS u JOIN Posts AS p ON p.OwnerUserId = u.Id INNER JOIN Posts AS q ON q.Id = p.ParentId WHERE LOWER(u.Location) LIKE LOWER('%##CountryName##%') AND p.PostTypeId = 2 AND q.Tags LIKE LOWER('%<##TagName##>%') GROUP BY p.OwnerUserId ORDER BY SUM(p.Score) DESC
### Instruction: what is the name of the medicine patient 022-158213 was allergic to in 05/last year? ### Response:
SELECT allergy.drugname FROM allergy WHERE allergy.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '022-158213')) AND DATETIME(allergy.allergytime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', allergy.allergytime) = '05'
### Instruction: what ground transportation is available from the PITTSBURGH airport to the town ### Response:
SELECT DISTINCT ground_service.transport_type FROM airport, airport_service, city AS CITY_0, city AS CITY_1, ground_service WHERE airport.airport_code = airport_service.airport_code AND CITY_0.city_code = airport_service.city_code AND CITY_0.city_name = 'PITTSBURGH' AND CITY_1.city_name = 'PITTSBURGH' AND ground_service.airport_code = airport.airport_code AND ground_service.city_code = CITY_1.city_code
### Instruction: what is the name of a procedure that patient 004-86136 has been given for two or more times in their current hospital encounter? ### Response:
SELECT t1.treatmentname FROM (SELECT treatment.treatmentname, COUNT(treatment.treatmenttime) AS c1 FROM treatment WHERE treatment.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)) GROUP BY treatment.treatmentname) AS t1 WHERE t1.c1 >= 2
### Instruction: tell me the time when patient 005-87465 was first diagnosed with brain tumor since 4 years ago? ### 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 = '005-87465')) AND diagnosis.diagnosisname = 'brain tumor' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-4 year') ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: on the last intensive care unit visit', what was last systemicdiastolic value of patient 030-53416? ### Response:
SELECT vitalperiodic.systemicdiastolic FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '030-53416') AND NOT patient.unitdischargetime IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1) AND NOT vitalperiodic.systemicdiastolic IS NULL ORDER BY vitalperiodic.observationtime DESC LIMIT 1
### Instruction: did patient 65124 receive hemorrhage complic proc diagnosis until 1 year ago? ### Response:
SELECT COUNT(*) > 0 FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'hemorrhage complic proc') AND diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 65124) AND DATETIME(diagnoses_icd.charttime) <= DATETIME(CURRENT_TIME(), '-1 year')
### Instruction: what medication was first prescribed to patient 021-250695 via oral rinse route until 11/2105? ### 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 = '021-250695')) AND medication.routeadmin = 'oral rinse' AND STRFTIME('%y-%m', medication.drugstarttime) <= '2105-11' ORDER BY medication.drugstarttime LIMIT 1
### Instruction: This semester , Thermodynamics and Kinetics is taught by whom ? ### Response:
SELECT DISTINCT instructor.name FROM instructor INNER JOIN offering_instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN course_offering ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN course ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE course.name LIKE '%Thermodynamics and Kinetics%' AND semester.semester = 'WN' AND semester.year = 2016
### Instruction: did patient 7533 had urine out foley output until 05/2104? ### Response:
SELECT COUNT(*) > 0 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 = 7533)) AND outputevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'urine out foley' AND d_items.linksto = 'outputevents') AND STRFTIME('%y-%m', outputevents.charttime) <= '2104-05'
### Instruction: when was the first time patient 002-21509 was until 4 years ago diagnosed with hyperglycemia? ### 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 = '002-21509')) AND diagnosis.diagnosisname = 'hyperglycemia' AND DATETIME(diagnosis.diagnosistime) <= DATETIME(CURRENT_TIME(), '-4 year') ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: did patient 002-3736's respiration ever greater than 24.0 a month before. ### 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 = '002-3736')) AND vitalperiodic.respiration > 24.0 AND NOT vitalperiodic.respiration IS NULL AND DATETIME(vitalperiodic.observationtime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month')
### Instruction: what was the name of the intake that patient 017-83061 until 943 days ago last had? ### 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 = '017-83061')) AND intakeoutput.cellpath LIKE '%intake%' AND DATETIME(intakeoutput.intakeoutputtime) <= DATETIME(CURRENT_TIME(), '-943 day') ORDER BY intakeoutput.intakeoutputtime DESC LIMIT 1
### Instruction: what was patient 006-81423's first diagnosis of acute renal failure time in the last hospital encounter? ### 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-81423' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1)) AND diagnosis.diagnosisname = 'acute renal failure' ORDER BY diagnosis.diagnosistime LIMIT 1
### Instruction: Questions and Answers per month. ### Response:
SELECT DATEADD(month, DATEDIFF(month, @start, CreationDate), @start) AS "month", SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS "questions", SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS "answers" FROM Posts WHERE (PostTypeId = 1 OR PostTypeId = 2) AND CreationDate >= @start AND CreationDate < @stop AND Score = 0 GROUP BY DATEADD(month, DATEDIFF(month, @start, CreationDate), @start) ORDER BY DATEADD(month, DATEDIFF(month, @start, CreationDate), @start)
### Instruction: when is the first time patient 006-254182 was prescribed a medication via inpl route until 15 months ago? ### Response:
SELECT medication.drugstarttime FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-254182')) AND medication.routeadmin = 'inpl' AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-15 month') ORDER BY medication.drugstarttime LIMIT 1
### Instruction: What are the class numbers Dr. Tessa Brown is doing in the next semester ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND instructor.name LIKE '%Tessa Brown%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: is the arterial bp mean of patient 5849 normal? ### Response:
SELECT COUNT(*) > 0 FROM chartevents WHERE chartevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 5849)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'arterial bp mean' AND d_items.linksto = 'chartevents') AND chartevents.valuenum BETWEEN mean_bp_lower AND mean_bp_upper
### Instruction: has patient 032-18678's respiration been less today than 21.0? ### 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-18678')) AND vitalperiodic.respiration < 21.0 AND NOT vitalperiodic.respiration IS NULL AND DATETIME(vitalperiodic.observationtime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-0 day')
### Instruction: what is the average value of ptt in patient 55503's body in 11/last year? ### Response:
SELECT AVG(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 55503) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'ptt') AND DATETIME(labevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', labevents.charttime) = '11'
### Instruction: what has been the total amount of input patient 006-200601 received on 09/20/2104? ### Response:
SELECT SUM(intakeoutput.cellvaluenumeric) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-200601')) AND intakeoutput.cellpath LIKE '%intake%' AND STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime) = '2104-09-20'
### Instruction: what is the first procedure that patient 95088 received during the previous year? ### Response:
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT procedures_icd.icd9_code FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 95088) AND DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') ORDER BY procedures_icd.charttime LIMIT 1)
### Instruction: Are there any courses being taught by Dr. Pedro Sanchez next semester ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND instructor.name LIKE '%Pedro Sanchez%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: What is my accepted answer percentage rate?. What is my accepted answer percentage rate On avg how often are answers I give, accepted. ---- Original source: https://data.stackexchange.com/stackoverflow/query/949/what-is-my-accepted-answer-percentage-rate ### Response:
SELECT (CAST(COUNT(a.Id) AS FLOAT) / (SELECT COUNT(*) FROM Posts WHERE OwnerUserId = @UserId AND PostTypeId = 2) * 100) AS AcceptedPercentage FROM Posts AS q INNER JOIN Posts AS a ON q.AcceptedAnswerId = a.Id WHERE a.OwnerUserId = @UserId AND a.PostTypeId = 2
### Instruction: what is the maximum total cost for the hospital involving a procedure called valve replacement or repair - routine during the last year? ### Response:
SELECT MAX(t1.c1) FROM (SELECT SUM(cost.cost) AS c1 FROM cost WHERE cost.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.patientunitstayid IN (SELECT treatment.patientunitstayid FROM treatment WHERE treatment.treatmentname = 'valve replacement or repair - routine')) AND DATETIME(cost.chargetime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: Do you know what Dr. Richard Valliant is teaching next semester ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND instructor.name LIKE '%Richard Valliant%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: what is the monthly maximum value of patient 027-168760's urinary creatinine on their first hospital visit? ### Response:
SELECT MAX(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-168760' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND lab.labname = 'urinary creatinine' GROUP BY STRFTIME('%y-%m', lab.labresulttime)
### Instruction: what was the name of the output the last time patient 51177 had since 08/01/2101? ### Response:
SELECT d_items.label FROM d_items WHERE d_items.itemid IN (SELECT outputevents.itemid 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 = 51177)) AND STRFTIME('%y-%m-%d', outputevents.charttime) >= '2101-08-01' ORDER BY outputevents.charttime DESC LIMIT 1)
### Instruction: DENTHYG 220 had who for GSIs last semester ? ### Response:
SELECT DISTINCT student.firstname, student.lastname FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN gsi ON gsi.course_offering_id = course_offering.offering_id INNER JOIN student ON student.student_id = gsi.student_id INNER JOIN semester ON semester.semester_id = course_offering.semester WHERE course.department = 'DENTHYG' AND course.number = 220 AND semester.semester = 'FA' AND semester.year = 2015
### Instruction: number of posts per day of week over the years. ### Response:
SELECT COUNT(*) AS "all", SUM(CASE WHEN CreationDate BETWEEN DATEADD(yy, -1, GETDATE()) AND GETDATE() THEN 1 ELSE 0 END) AS "year", SUM(CASE WHEN CreationDate BETWEEN DATEADD(m, -1, GETDATE()) AND GETDATE() THEN 1 ELSE 0 END) AS "month", SUM(CASE WHEN CreationDate BETWEEN DATEADD(wk, -1, GETDATE()) AND GETDATE() THEN 1 ELSE 0 END) AS "week", DATEPART(dw, CreationDate) AS "day_of_week" FROM Posts GROUP BY DATEPART(dw, CreationDate)
### Instruction: Top users by average non-deleted answer score. List of top users by average non-deleted and non-community wiki answer score. ### Response:
SELECT Users.Id AS "user_link", COUNT(Posts.Id) AS Answers, CAST(AVG(CAST(Score AS FLOAT)) AS FLOAT(6, 2)) AS "average_answer_score" FROM Posts INNER JOIN Users ON Users.Id = OwnerUserId WHERE PostTypeId = 2 AND CommunityOwnedDate IS NULL AND ClosedDate IS NULL GROUP BY Users.Id, DisplayName HAVING COUNT(Posts.Id) > '##MinAnswers##' ORDER BY 'average_answer_score' DESC LIMIT 100
### Instruction: How many courses for each course description? Show me a stacked bar chart The x-axis is course description and group by office name, 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 JOIN PROFESSOR AS T4 ON T2.EMP_NUM = T4.EMP_NUM GROUP BY PROF_OFFICE, CRS_DESCRIPTION ORDER BY COUNT(CRS_DESCRIPTION)
### Instruction: tell me the name of an output that patient 53863 has last had until 03/15/2101? ### Response:
SELECT d_items.label FROM d_items WHERE d_items.itemid IN (SELECT outputevents.itemid 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 = 53863)) AND STRFTIME('%y-%m-%d', outputevents.charttime) <= '2101-03-15' ORDER BY outputevents.charttime DESC LIMIT 1)
### Instruction: Usuarios con 10 o m s preguntas sin aceptar. ### Response:
SELECT U.Id, U.DisplayName, COUNT(CASE WHEN P.AcceptedAnswerId IS NULL THEN 1 ELSE NULL END) AS PreguntasSinAceptar, COUNT(CASE WHEN NOT P.AcceptedAnswerId IS NULL THEN 1 ELSE NULL END) AS PreguntasAceptadas FROM Users AS U INNER JOIN Posts AS P ON U.Id = P.OwnerUserId WHERE P.PostTypeId = 1 AND P.AnswerCount > 0 GROUP BY U.Id, U.DisplayName HAVING COUNT(CASE WHEN P.AcceptedAnswerId IS NULL THEN 1 ELSE NULL END) >= 10 ORDER BY 3 DESC
### Instruction: get number answers after time t. ### Response:
SELECT QuestionPost.Id, SUM(CASE WHEN AnsweringPostWithinInterval.Id IS NULL THEN 0 ELSE 1 END) AS num_answering_after_t FROM Posts AS QuestionPost LEFT JOIN Posts AS AnsweringPostWithinInterval ON AnsweringPostWithinInterval.ParentId = QuestionPost.Id AND AnsweringPostWithinInterval.CreationDate > DATEADD(dd, 1, QuestionPost.CreationDate) AND AnsweringPostWithinInterval.ClosedDate IS NULL WHERE QuestionPost.PostTypeId = (SELECT Id FROM PostTypes WHERE Name = 'Question') AND QuestionPost.ClosedDate IS NULL AND QuestionPost.Id % 158 = 0 GROUP BY QuestionPost.Id
### Instruction: What are the section offerings for SPANISH 562 after 08:30 P.M. ? ### Response:
SELECT DISTINCT course_offering.end_time, course_offering.section_number, course_offering.start_time FROM course, course_offering, semester WHERE course_offering.start_time > '08:30' AND course.course_id = course_offering.course_id AND course.department = 'SPANISH' AND course.number = 562 AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: Votes before and after entry on the HNQ list. ### Response:
SELECT CASE WHEN v.CreationDate < ph.CreationDate THEN 'pre' ELSE 'post' END AS epoch, vt.Name, COUNT(*) AS votes FROM PostHistory AS ph JOIN Posts AS p ON ph.PostId = COALESCE(p.ParentId, p.Id) JOIN Votes AS v ON v.PostId = p.Id JOIN VoteTypes AS vt ON VoteTypeId = vt.Id WHERE PostHistoryTypeId IN (52) GROUP BY CASE WHEN v.CreationDate < ph.CreationDate THEN 'pre' ELSE 'post' END, vt.Name, vt.Id ORDER BY vt.Id, epoch DESC
### Instruction: how many time did patient 022-3289 produce a urinary catheter output: urethral output in their first hospital encounter? ### Response:
SELECT COUNT(*) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '022-3289' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1)) AND intakeoutput.cellpath LIKE '%output%' AND intakeoutput.celllabel = 'urinary catheter output: urethral'
### Instruction: what's the minimum cost of a hospital that includes a drug called aspirin 81 mg po chew 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 medication.patientunitstayid FROM medication WHERE medication.drugname = 'aspirin 81 mg po chew')) AND STRFTIME('%y', cost.chargetime) <= '2104' GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: Close and reopen votes by week. ### Response:
SELECT DATEADD(week, DATEDIFF(week, @start, CreationDate), @start) AS "week", SUM(CASE WHEN PostHistoryTypeId = 10 THEN 1 ELSE 0 END) AS "closevotes", SUM(CASE WHEN PostHistoryTypeId = 11 THEN 1 ELSE 0 END) AS "reopenvotes" FROM PostHistory WHERE PostHistoryTypeId IN (10, 11) AND CreationDate >= @start AND CreationDate < @stop GROUP BY DATEADD(week, DATEDIFF(week, @start, CreationDate), @start) ORDER BY DATEADD(week, DATEDIFF(week, @start, CreationDate), @start)
### Instruction: Tags with a high proportion of unanswered questions. with score <= 0, low views, no answers ### Response:
SELECT t.TagName, 100 * CAST(COUNT(p.Id) AS FLOAT) / COUNT(*) AS "% Unanswered", COUNT(p.Id) AS Unanswered, COUNT(*) AS Posts FROM Tags AS t LEFT JOIN PostTags AS pt ON t.Id = pt.TagId LEFT OUTER JOIN Posts AS p ON pt.PostId = p.Id AND p.PostTypeId = 1 AND p.ViewCount < 500 AND (p.AnswerCount < 1 OR p.AnswerCount IS NULL) GROUP BY t.TagName HAVING COUNT(*) > 2000 ORDER BY 2 DESC
### Instruction: in 2105, patient 005-87465 underwent a medicine consultation procedure in other hospitals? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.uniquepid = '005-87465' AND patient.hospitalid <> (SELECT DISTINCT patient.hospitalid FROM patient WHERE patient.uniquepid = '005-87465' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'medicine consultation' AND STRFTIME('%y', treatment.treatmenttime) = '2105'
### Instruction: what is the average hospital cost that involves a open biopsy soft tissue in 2100? ### 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 = 'open biopsy soft tissue')) AND STRFTIME('%y', cost.chargetime) = '2100' GROUP BY cost.hadm_id) AS t1
### Instruction: what's the name of the diagnosis that patient 77177 was given for the first time until 2101? ### Response:
SELECT d_icd_diagnoses.short_title FROM d_icd_diagnoses WHERE d_icd_diagnoses.icd9_code IN (SELECT diagnoses_icd.icd9_code FROM diagnoses_icd WHERE diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 77177) AND STRFTIME('%y', diagnoses_icd.charttime) <= '2101' ORDER BY diagnoses_icd.charttime LIMIT 1)
### Instruction: did patient 54825 undergo until 1 year ago a rt/left heart card cath procedure? ### Response:
SELECT COUNT(*) > 0 FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'rt/left heart card cath') AND procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 54825) AND DATETIME(procedures_icd.charttime) <= DATETIME(CURRENT_TIME(), '-1 year')
### Instruction: when did patient 67005 last get stool microbiology test in 08/last year? ### Response:
SELECT microbiologyevents.charttime FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 67005) AND microbiologyevents.spec_type_desc = 'stool' AND DATETIME(microbiologyevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', microbiologyevents.charttime) = '08' ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: what is patient 82132 first diagnosis time of schizoaffective dis nos during the current hospital visit? ### Response:
SELECT diagnoses_icd.charttime FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'schizoaffective dis nos') AND diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 82132 AND admissions.dischtime IS NULL) ORDER BY diagnoses_icd.charttime LIMIT 1
### Instruction: what are the three most frequently given procedures for patients with age 60 or above? ### Response:
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT t1.icd9_code FROM (SELECT procedures_icd.icd9_code, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.age >= 60) GROUP BY procedures_icd.icd9_code) AS t1 WHERE t1.c1 <= 3)