instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: Which 2011 12 has a 2010 11 smaller than 26.016, and a Rank 2013 larger than 20, and a Club of rubin kazan? ### Response:
SELECT AVG("2011\u201312") FROM table_58615 WHERE "2010\u201311" < '26.016' AND "Rank 2013" > '20' AND "Club" = 'rubin kazan'
### Instruction: Distribution of number of votes on questions. ### Response:
WITH a AS (SELECT p.Id, COUNT(v.PostId) AS n_votes FROM Votes AS v FULL OUTER JOIN Posts AS p ON v.PostId = p.Id WHERE p.PostTypeId IN (1) AND v.VoteTypeId IN (2, 3) GROUP BY p.Id), b AS (SELECT pp.Id, n_votes FROM a FULL OUTER JOIN Posts AS pp ON a.Id = pp.Id WHERE pp.PostTypeId IN (1)) SELECT * FROM b ORDER BY Id DESC
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, draw a line chart about the change of manager_id over hire_date , could you show x axis from low to high order? ### Response:
SELECT HIRE_DATE, MANAGER_ID FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY HIRE_DATE
### Instruction: how many hours have passed since the first time patient 71689 stayed in careunit sicu in the current hospital encounter. ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', transfers.intime)) FROM transfers WHERE transfers.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 71689 AND admissions.dischtime IS NULL) AND transfers.careunit = 'sicu' ORDER BY transfers.intime LIMIT 1
### Instruction: Posts with broken Chabadlibrary.org links. ### Response:
SELECT p.Id AS "post_link", (CASE WHEN NOT p.Title IS NULL THEN p.Title ELSE pq.Title END) AS title, p.CreationDate, p.LastActivityDate, p.Score, (CASE WHEN NOT p.ViewCount IS NULL THEN p.ViewCount ELSE pq.ViewCount END) AS viewcount FROM Posts AS p LEFT OUTER JOIN Posts AS pq ON pq.Id = p.ParentId WHERE p.Body LIKE '%chabadlibrary.org%furl=%' ORDER BY ViewCount DESC
### Instruction: no evidence of chronic renal failure or significant proteinuria ( serum creatinine < 1.6 mg / dl, creatinine clearance > 80 ml / min, and albumin excretion < / = 300 mg / 24 hr ) ### Response:
SELECT * FROM table_dev_18 WHERE renal_disease = 0 OR significant_proteinuria = 0 OR (serum_creatinine < 1.6 AND creatinine_clearance_cl > 80 AND albumin_excretion <= 300)
### Instruction: provide the number of patients whose diagnoses long title is closed fracture of subtrochanteric section of neck of femur and lab test category is hematology? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.long_title = "Closed fracture of subtrochanteric section of neck of femur" AND lab."CATEGORY" = "Hematology"
### Instruction: how many patients whose diagnoses long title is methicillin resistant staphylococcus aureus septicemia and drug route is ou? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE diagnoses.long_title = "Methicillin resistant Staphylococcus aureus septicemia" AND prescriptions.route = "OU"
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, a bar chart shows the distribution of job_id and the sum of employee_id , and group by attribute job_id. ### Response:
SELECT JOB_ID, SUM(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID
### Instruction: What is the average public debt % of GDP in 2013 Q1 of the country with a member slate sorted by GDP of Czech Republic and a GDP per capita in PPP US dollars in 2012 greater than 27,191? ### Response:
SELECT AVG("Public Debt % of GDP (2013 Q1)") FROM table_75810 WHERE "Member State sorted by GDP" = 'czech republic' AND "GDP per capita in PPP US$ (2012)" > '27,191'
### Instruction: Is EMBA 640 available right now ? ### Response:
SELECT COUNT(*) > 0 FROM course, course_offering, offering_instructor, semester WHERE course.course_id = course_offering.course_id AND course.department = 'EMBA' AND course.number = 640 AND offering_instructor.offering_id = course_offering.offering_id AND semester.semester = 'WN' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: what are the top five most common laboratory tests performed in this year? ### 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 DATETIME(labevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') GROUP BY labevents.itemid) AS t1 WHERE t1.c1 <= 5)
### Instruction: Percentage answer rate per tag, ordered. ### Response:
SELECT t.TagName AS Tag, ROUND(SUM(CASE WHEN NOT AcceptedAnswerId IS NULL THEN 1 ELSE 0 END) * 100.0 / COUNT(1), 2) AS "percent_answered" FROM Posts AS p INNER JOIN PostTags AS pt ON p.Id = pt.PostId INNER JOIN Tags AS t ON pt.TagId = t.Id WHERE p.PostTypeId = 1 AND t.TagName = 'office-js' GROUP BY t.Id, t.TagName ORDER BY 'percent_answered'
### Instruction: Cross platform technology stacks communities unanswered posts. ### Response:
SELECT COUNT(p.Id) AS UnansweredPosts, tg.TagName FROM Posts AS p INNER JOIN PostTags AS t ON p.Id = t.PostId INNER JOIN Tags AS tg ON tg.Id = t.TagId WHERE tg.TagName IN ('react-native', 'xamarin', 'flutter', 'kotlin', 'cordova', 'titanium', 'ionic-framework', 'javascript') AND p.PostTypeId = 1 AND (AnswerCount IS NULL OR AnswerCount = 0) GROUP BY tg.TagName
### Instruction: New Questions Analysis by Month. ### Response:
SELECT YEAR(CreationDate) AS "year", MONTH(CreationDate) AS "month", SUM(CASE WHEN Posts.PostTypeId = 1 THEN 1 ELSE 0 END) AS QuestionCount, SUM(CASE WHEN Posts.PostTypeId = 2 THEN 1 ELSE 0 END) AS AnswerCount FROM Posts WHERE YEAR(CreationDate) >= 2014 GROUP BY YEAR(CreationDate), MONTH(CreationDate) ORDER BY YEAR(CreationDate), MONTH(CreationDate)
### Instruction: which topics were most popular at ACL 2014 ### Response:
SELECT DISTINCT COUNT(paper.paperid), keyphrase.keyphraseid FROM keyphrase, paper, paperkeyphrase, venue WHERE paperkeyphrase.keyphraseid = keyphrase.keyphraseid AND paper.paperid = paperkeyphrase.paperid AND paper.year = 2014 AND venue.venueid = paper.venueid AND venue.venuename = 'ACL' GROUP BY keyphrase.keyphraseid ORDER BY COUNT(paper.paperid) DESC
### Instruction: until 06/2105 what was the first time patient 80119 had a medication via iv drip route prescribed? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 80119) AND prescriptions.route = 'iv drip' AND STRFTIME('%y-%m', prescriptions.startdate) <= '2105-06' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: tell me the name of the drug that was last prescribed to patient 12938 in 03/2104 via tp route? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 12938) AND prescriptions.route = 'tp' AND STRFTIME('%y-%m', prescriptions.startdate) = '2104-03' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: what is the total amount of furosemide that has been prescribed to patient 72909 this month? ### Response:
SELECT SUM(prescriptions.dose_val_rx) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 72909) AND prescriptions.drug = 'furosemide' AND DATETIME(prescriptions.startdate, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month')
### Instruction: did patient 17237 have any microbiological test result in 05/last year? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17237) AND DATETIME(microbiologyevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', microbiologyevents.charttime) = '05'
### Instruction: tell me the test that was last given to patient 29410 in 11/2102? ### 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 = 29410) AND STRFTIME('%y-%m', labevents.charttime) = '2102-11' ORDER BY labevents.charttime DESC LIMIT 1)
### Instruction: what is the minimum amount of hospital cost that includes macrophages until 2103? ### 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 = 'macrophages')) AND STRFTIME('%y', cost.chargetime) <= '2103' GROUP BY cost.hadm_id) AS t1
### Instruction: what was the last medication patient 73693 was prescribed via iv drip last month? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 73693) AND prescriptions.route = 'iv drip' AND DATETIME(prescriptions.startdate, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: have any microbiological tests been done for patient 031-1337 since 2 years ago? ### 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-1337')) AND DATETIME(microlab.culturetakentime) >= DATETIME(CURRENT_TIME(), '-2 year')
### Instruction: For the ULCS requirement what class is the easiest ? ### Response:
SELECT DISTINCT course.department, course.name, course.number, program_course.workload, program_course.workload FROM course, program_course WHERE program_course.category LIKE '%ULCS%' 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 '%ULCS%')
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, visualize a bar chart about the distribution of job_id and the sum of department_id , and group by attribute job_id. ### Response:
SELECT JOB_ID, SUM(DEPARTMENT_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID
### Instruction: what would be patient 016-38131's monthly maximum weight since 2105? ### Response:
SELECT MAX(patient.admissionweight) FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '016-38131') AND NOT patient.admissionweight IS NULL AND STRFTIME('%y', patient.unitadmittime) >= '2105' GROUP BY STRFTIME('%y-%m', patient.unitadmittime)
### Instruction: since 06/2105 has patient 022-198713 had any allergies? ### 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 = '022-198713')) AND STRFTIME('%y-%m', allergy.allergytime) >= '2105-06'
### Instruction: Top Users by Badges and Location. ### Response:
SELECT OwnerUserId AS "user_link", PostTypeId, ParentId, Score FROM Posts WHERE OwnerUserId IN (SELECT Id FROM Users WHERE LOWER(Location) LIKE '%##Location##%' OR UPPER(Location) LIKE '%##Location##%') AND ((LOWER(Tags) LIKE '%##Tags##%' OR UPPER(Tags) LIKE '%##Tags##%') OR (ParentId IN (SELECT Id FROM Posts WHERE LOWER(Tags) LIKE '%##Tags##%' OR UPPER(Tags) LIKE '%##Tags##%')))
### Instruction: hyperlipidemia ( fasting total cholesterol > 240 mg / dl and / or fasting triglycerides > 200 mg / dl and / or fasting ldl cholesterol > 140 mg / dl ) ; ### Response:
SELECT * FROM table_train_248 WHERE hyperlipidemia = 1 OR (fasting_total_cholesterol > 240 OR fasting_triglycerides > 200 OR fasting_ldl_cholesterol > 140)
### Instruction: In Spring 2018 , in the afternoon , will 101 be available ? ### Response:
SELECT COUNT(*) > 0 FROM course, course_offering, semester WHERE course_offering.start_time >= '12:00:00' AND course.course_id = course_offering.course_id AND course.department = 'EECS' AND course.number = 101 AND semester.semester = 'Spring' AND semester.semester_id = course_offering.semester AND semester.year = 2018
### Instruction: How many SO answers per month?. ### Response:
SELECT u.DisplayName, MONTH(p.CreationDate) + YEAR(p.CreationDate) * 100 AS "mdate", COUNT(u.DisplayName) AS "num" FROM Posts AS p, Users AS u WHERE p.PostTypeId = 2 AND p.OwnerUserId IN ('##SOid##') AND p.OwnerUserId = u.Id GROUP BY MONTH(p.CreationDate) + YEAR(p.CreationDate) * 100, u.DisplayName ORDER BY Num DESC
### Instruction: Posts where last event was CW-ification and it wasn't done by the OP. ### Response:
SELECT ph.PostId AS "post_link", revisions = 'site://posts/' + CAST(ph.PostId AS TEXT) + '/revisions' FROM PostHistory AS ph INNER JOIN Posts AS p ON p.Id = ph.PostId WHERE (ph.PostHistoryTypeId = 16) AND (ph.UserId != p.OwnerUserId) AND ph.Id IN (SELECT MAX(Id) AS last FROM PostHistory GROUP BY PostId) ORDER BY ph.PostId DESC
### Instruction: List users by city with posts including specific tags. ### Response:
SELECT u.Id AS "user_link", * FROM (SELECT DISTINCT p.OwnerUserId FROM (SELECT * FROM (SELECT * FROM Tags AS t WHERE LOWER(t.TagName) LIKE '%##tag##%') AS tgs JOIN PostTags AS pt ON tgs.Id = pt.TagId) AS pt JOIN Posts AS p ON pt.PostId = p.Id) AS p JOIN Users AS u ON p.OwnerUserId = u.Id WHERE LOWER(u.Location) LIKE 'Bardufoss, Norge'
### Instruction: Find the names of stadiums that some Australian swimmers have been to, and count them by a bar chart, and order by the X from low to high. ### Response:
SELECT T4.Name, COUNT(T4.Name) FROM swimmer AS t1 JOIN record AS t2 ON t1.ID = t2.Swimmer_ID JOIN event AS t3 ON t2.Event_ID = t3.ID JOIN stadium AS t4 ON t4.ID = t3.Stadium_ID WHERE t1.Nationality = 'Australia' GROUP BY T4.Name ORDER BY T4.Name
### Instruction: when last patient 021-25408 had a procedure since 2105? ### Response:
SELECT treatment.treatmenttime FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-25408')) AND STRFTIME('%y', treatment.treatmenttime) >= '2105' ORDER BY treatment.treatmenttime DESC LIMIT 1
### Instruction: how many times do patient 002-62783 get a magnesium test until 2103? ### 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 = '002-62783')) AND lab.labname = 'magnesium' AND STRFTIME('%y', lab.labresulttime) <= '2103'
### Instruction: how much magnesium sulfate was prescribed for the first time on their last hospital visit to patient 44451? ### Response:
SELECT prescriptions.dose_val_rx FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 44451 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND prescriptions.drug = 'magnesium sulfate' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: how many hours has it been since patient 24132 stayed for the first time on this hospital visit in careunit micu? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', transfers.intime)) FROM transfers WHERE transfers.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 24132 AND admissions.dischtime IS NULL) AND transfers.careunit = 'micu' ORDER BY transfers.intime LIMIT 1
### Instruction: how much does it cost to check for nonsp abn find-gu organs? ### Response:
SELECT DISTINCT cost.cost FROM cost WHERE cost.event_type = 'diagnoses_icd' AND cost.event_id IN (SELECT diagnoses_icd.row_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 = 'nonsp abn find-gu organs'))
### Instruction: how much metronidazole is prescribed to patient 5905 last time until 48 months ago? ### Response:
SELECT prescriptions.dose_val_rx FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 5905) AND prescriptions.drug = 'metronidazole' AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-48 month') ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: what was the name of the specimen test that patient 85895 has gotten the first the last month? ### Response:
SELECT microbiologyevents.spec_type_desc FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 85895) AND DATETIME(microbiologyevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY microbiologyevents.charttime LIMIT 1
### Instruction: Which class could be the easiest to fulfill the Other 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 '%Other%' 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 '%Other%')
### Instruction: Angular vs Ember vs React last Month. ### Response:
SELECT rate.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS Rank, rate.Rate AS NumQuestions FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate > DATEADD(Month, -1, GETDATE()) AND TagName IN ('angularjs', 'ember.js', 'reactjs') GROUP BY TagName) AS rate ORDER BY rate.rate DESC
### Instruction: how many times did patient 26057 take a lab immunoglobulin m test in 2105? ### Response:
SELECT COUNT(*) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'immunoglobulin m') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 26057) AND STRFTIME('%y', labevents.charttime) = '2105'
### Instruction: how many hours have passed since patient 2957 stayed in the careunit sicu on this hospital encounter for the first time? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', transfers.intime)) FROM transfers WHERE transfers.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 2957 AND admissions.dischtime IS NULL) AND transfers.careunit = 'sicu' ORDER BY transfers.intime LIMIT 1
### Instruction: count the number of patients whose admission type is elective and diagnoses long title is personal history of malignant neoplasm of rectum, rectosigmoid junction, and anus? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.admission_type = "ELECTIVE" AND diagnoses.long_title = "Personal history of malignant neoplasm of rectum, rectosigmoid junction, and anus"
### Instruction: what is the name of the lab test that is patient 80671 first received since 54 months ago? ### 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 = 80671) AND DATETIME(labevents.charttime) >= DATETIME(CURRENT_TIME(), '-54 month') ORDER BY labevents.charttime LIMIT 1)
### Instruction: how many hours has it been since the last time patient 31854 visited careunit ccu during this hospital visit? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', transfers.intime)) FROM transfers WHERE transfers.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 31854 AND admissions.dischtime IS NULL) AND transfers.careunit = 'ccu' ORDER BY transfers.intime DESC LIMIT 1
### Instruction: what are the numbers of patients who had ns .9% intake? ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT icustays.hadm_id FROM icustays WHERE icustays.icustay_id IN (SELECT inputevents_cv.icustay_id FROM inputevents_cv WHERE inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'ns .9%' AND d_items.linksto = 'inputevents_cv')))
### Instruction: what was the diagnosis of patient 025-44842 for the last time during their current 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 = '025-44842' AND patient.hospitaldischargetime IS NULL)) ORDER BY diagnosis.diagnosistime DESC LIMIT 1
### Instruction: Next semester , is there an RCLANG 293 section not on Monday ? ### Response:
SELECT DISTINCT course_offering.section_number FROM course, course_offering, semester WHERE course_offering.monday = 'N' AND course.course_id = course_offering.course_id AND course.department = 'RCLANG' AND course.number = 293 AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: in 2105 was there any microbiological test history of patient 031-17834? ### 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-17834')) AND STRFTIME('%y', microlab.culturetakentime) = '2105'
### Instruction: give me the number of patients with aortic valve insufficiency/aortic valve replacement/sda who had other incision with drainage of skin and subcutaneous tissue. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.diagnosis = "AORTIC VALVE INSUFFIENCY\AORTIC VALVE REPLACEMENT /SDA" AND procedures.short_title = "Other skin & subq i & d"
### Instruction: Who teaches courses that fulfill a Core program requirement ? ### 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 program_course ON program_course.course_id = course_offering.course_id INNER JOIN program ON program.program_id = program_course.program_id WHERE program.name LIKE '%Core%'
### Instruction: Question pairs closed as the dupe of each other. ### Response:
SELECT A.PostId AS "post_link", B.PostId AS "post_link" FROM PostLinks AS A, PostLinks AS B, Posts AS D, Posts AS O WHERE A.PostId = D.Id AND A.RelatedPostId = B.PostId AND B.RelatedPostId = A.PostId AND A.LinkTypeId = 3 AND B.LinkTypeId = 3 AND B.PostId = O.Id AND A.PostId < B.PostId ORDER BY A.PostId
### Instruction: Number of questions by people with the Informed badge. ### Response:
SELECT p.OwnerUserId AS Owner, p.Id AS "post_link", CASE WHEN NOT b.Id IS NULL THEN 1 ELSE 0 END AS Informed, CASE WHEN b.Id IS NULL THEN 1 ELSE 0 END AS Uninformed, p.Score, p.ViewCount AS Views FROM Posts AS p LEFT OUTER JOIN Badges AS b ON b.UserId = p.OwnerUserId AND b.Name = 'Informed' WHERE p.PostTypeId = 1 ORDER BY p.OwnerUserId DESC
### Instruction: How many students taking a course who received an A or C? Group by students' first name with a bar chart, and show by the how many stu fname in asc please. ### Response:
SELECT STU_FNAME, COUNT(STU_FNAME) FROM STUDENT AS T1 JOIN ENROLL AS T2 ON T1.STU_NUM = T2.STU_NUM WHERE T2.ENROLL_GRADE = 'C' OR T2.ENROLL_GRADE = 'A' GROUP BY STU_FNAME ORDER BY COUNT(STU_FNAME)
### Instruction: what is first weight of patient 006-158338 in this month. ### Response:
SELECT patient.admissionweight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-158338') AND NOT patient.admissionweight IS NULL AND DATETIME(patient.unitadmittime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') ORDER BY patient.unitadmittime LIMIT 1
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, draw a line chart about the change of department_id over hire_date , and show by the x-axis in desc. ### Response:
SELECT HIRE_DATE, DEPARTMENT_ID FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY HIRE_DATE DESC
### Instruction: what was the total number of outputs of patient 7533 until 09/20/2105? ### 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 = 7533)) AND STRFTIME('%y-%m-%d', outputevents.charttime) <= '2105-09-20'
### Instruction: How many papers were written on Multiuser Receiver in the Decision Feedback this year ? ### Response:
SELECT DISTINCT paper.paperid FROM keyphrase, paper, paperkeyphrase WHERE keyphrase.keyphrasename = 'Multiuser Receiver in the Decision Feedback' AND paperkeyphrase.keyphraseid = keyphrase.keyphraseid AND paper.paperid = paperkeyphrase.paperid AND paper.year = 2016 GROUP BY paper.paperid HAVING COUNT(DISTINCT keyphrase.keyphrasename) > 1
### Instruction: What are the country names, area and population which has both roller coasters with speed higher ### Response:
SELECT T1.name, T1.area, T1.population FROM country AS T1 JOIN roller_coaster AS T2 ON T1.Country_ID = T2.Country_ID WHERE T2.speed > 60 INTERSECT SELECT T1.name, T1.area, T1.population FROM country AS T1 JOIN roller_coaster AS T2 ON T1.Country_ID = T2.Country_ID WHERE T2.speed < 55
### Instruction: Find all the payment dates for the payments with an amount larger than 10 and the payments handled by a staff person with the first name Elsa, and count them by a bar chart, could you list from high to low by the Y-axis please? ### Response:
SELECT payment_date, COUNT(payment_date) FROM payment WHERE amount > 10 UNION SELECT T1.payment_date FROM payment AS T1 JOIN staff AS T2 ON T1.staff_id = T2.staff_id WHERE T2.first_name = 'Elsa' ORDER BY COUNT(payment_date) DESC
### Instruction: Edits that removed the mathematical-physics tag. ### Response:
SELECT edits.PostId AS "post_link", edits.CreationDate, edits.Text AS "Edited tags", originalTags.Text AS "Original tags" FROM PostHistory AS edits JOIN PostHistory AS originalTags ON originalTags.PostId = edits.PostId WHERE edits.PostHistoryTypeId = 6 AND originalTags.PostHistoryTypeId = 3 AND originalTags.Text LIKE '%mathematical-physics%' AND NOT edits.Text LIKE '%mathematical-physics%' ORDER BY edits.CreationDate DESC
### Instruction: is there anything patient 028-55503 has had a diagnosis with since 1 year ago? ### 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 = '028-55503')) AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-1 year')
### Instruction: tell me the total magnesium sulfate dose that patient 11426 has been prescribed until 36 months ago? ### Response:
SELECT SUM(prescriptions.dose_val_rx) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 11426) AND prescriptions.drug = 'magnesium sulfate' AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-36 month')
### Instruction: Which teachers offer courses that fulfill a Other program requirement ? ### 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 program_course ON program_course.course_id = course_offering.course_id INNER JOIN program ON program.program_id = program_course.program_id WHERE program.name LIKE '%Other%'
### Instruction: Find all first-grade students who are NOT taught by OTHA MOYER. Report their first and last names. ### Response:
SELECT DISTINCT T1.firstname, T1.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T1.grade = 1 EXCEPT SELECT T1.firstname, T1.lastname FROM list AS T1 JOIN teachers AS T2 ON T1.classroom = T2.classroom WHERE T2.firstname = "OTHA" AND T2.lastname = "MOYER"
### Instruction: Upvotes and downvotes over time. ### Response:
SELECT CONCAT(YEAR(CreationDate), '-', MONTH(CreationDate)) AS "Month", COUNT(PostId) AS "Posts", SUM(CASE VoteTypeId WHEN 2 THEN 1 ELSE 0 END) AS "Upvotes", SUM(CASE VoteTypeId WHEN 3 THEN 1 ELSE 0 END) AS "Downvotes" FROM Votes GROUP BY YEAR(CreationDate), MONTH(CreationDate) ORDER BY YEAR(CreationDate), MONTH(CreationDate)
### Instruction: Show storm name with at least two regions and 10 cities affected. ### Response:
SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING COUNT(*) >= 2 INTERSECT SELECT T1.name FROM storm AS T1 JOIN affected_region AS T2 ON T1.storm_id = T2.storm_id GROUP BY T1.storm_id HAVING SUM(T2.number_city_affected) >= 10
### Instruction: Does Sanghyun Lee ever teach LAW 740 ? ### Response:
SELECT COUNT(*) > 0 FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.department = 'LAW' AND course.number = 740 AND instructor.name LIKE '%Sanghyun Lee%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: had patient 029-584 had received medication during the previous year? ### 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 = '029-584')) AND DATETIME(medication.drugstarttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year')
### Instruction: did patient 2957 since 5 years ago have a alkaline phosphatase test? ### Response:
SELECT COUNT(*) > 0 FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'alkaline phosphatase') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 2957) AND DATETIME(labevents.charttime) >= DATETIME(CURRENT_TIME(), '-5 year')
### Instruction: did patient 004-86136 receive a heparin lock iv fluids process in their 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 = '004-86136' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'heparin lock iv fluids'
### Instruction: What is the number of clubs when the average is more than 18,571, there are fewer than 182 games and the total attendance is 3,140,280 in a year more recent than 1995? ### Response:
SELECT AVG("No. Of Clubs") FROM table_48867 WHERE "Average" > '18,571' AND "Games" < '182' AND "Total Attendance" = '3,140,280' AND "Season" > '1995'
### Instruction: How many courses for each teacher? Show me a bar chart, and rank by the bar in ascending. ### Response:
SELECT EMP_FNAME, COUNT(EMP_FNAME) 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 EMP_FNAME ORDER BY EMP_FNAME
### Instruction: How many professors whose office is located in DRE 102 are hired in each weekday? Return a bar chart, and I want to rank from high to low by the Y-axis. ### Response:
SELECT EMP_HIREDATE, COUNT(EMP_HIREDATE) FROM EMPLOYEE AS T1 JOIN PROFESSOR AS T2 ON T1.EMP_NUM = T2.EMP_NUM WHERE T2.PROF_OFFICE = 'DRE 102' GROUP BY EMP_LNAME ORDER BY COUNT(EMP_HIREDATE) DESC
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, draw a line chart about the change of commission_pct over hire_date , rank x axis in ascending order. ### Response:
SELECT HIRE_DATE, COMMISSION_PCT FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY HIRE_DATE
### Instruction: and what was the last time patient 2957 was prescribed medication using the iv drip route since 120 months ago? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 2957) AND prescriptions.route = 'iv drip' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-120 month') ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: give me the number of patients whose primary disease is atrial fibrillation\thoracoscopic maze procedure bilateral/sda and procedure icd9 code is 92? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.diagnosis = "ATRIAL FIBRILLATION\THORACOSCOPIC MAZE PROCEDURE BILATERAL/SDA" AND procedures.icd9_code = "92"
### Instruction: in this year has patient 035-2057 have had any allergy? ### 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 = '035-2057')) AND DATETIME(allergy.allergytime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year')
### Instruction: what were the allergies that patient 035-18116 had until 30 months ago. ### 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 = '035-18116')) AND DATETIME(allergy.allergytime) <= DATETIME(CURRENT_TIME(), '-30 month')
### Instruction: how many hours have passed since first time on the current hospital visit patient 14671 stayed in the careunit micu? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', transfers.intime)) FROM transfers WHERE transfers.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 14671 AND admissions.dischtime IS NULL) AND transfers.careunit = 'micu' ORDER BY transfers.intime LIMIT 1
### Instruction: tell me the name of an allergy patient 006-121423 has in the first hospital encounter? ### 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 = '006-121423' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1))
### Instruction: Median time of getting accepted answers. ### Response:
WITH diffs AS (SELECT CAST(a.CreationDate - q.CreationDate AS FLOAT) AS d FROM Posts AS q JOIN Posts AS a ON a.Id = q.AcceptedAnswerId) SELECT ((SELECT MAX(d) FROM (SELECT PERCENT AS d FROM diffs ORDER BY d LIMIT 50) AS BottomHalf) + (SELECT MIN(d) FROM (SELECT PERCENT AS d FROM diffs ORDER BY d DESC LIMIT 50) AS TopHalf)) / 2 AS Median
### Instruction: how much is the minimum total hospital cost that includes hypernatremia - etiology unknown? ### 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 = 'hypernatremia - etiology unknown')) GROUP BY cost.patienthealthsystemstayid) AS t1
### Instruction: Which 2008 09 has a 2012 13 of q, and a 2006 07 of q, and a 2007 08 of qf? ### Response:
SELECT "2008\u201309" FROM table_38551 WHERE "2012\u201313" = 'q' AND "2006\u201307" = 'q' AND "2007\u201308" = 'qf'
### Instruction: is there any microbiology test results for patient 025-44495 since 2103? ### Response:
SELECT COUNT(*) > 0 FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '025-44495')) AND STRFTIME('%y', microlab.culturetakentime) >= '2103'
### Instruction: Apache Spark Post Votes. ### Response:
SELECT p.Id, p.PostTypeId, p.ParentId, p.CreationDate, p.Score, p.ViewCount, p.Title, v.VoteTypeId, v.UserId, v.CreationDate FROM Posts AS p INNER JOIN Votes AS v ON v.PostId = p.Id WHERE p.Tags LIKE '%apache-spark%' AND v.CreationDate BETWEEN '2017-01-01' AND '2019-01-01' ORDER BY v.CreationDate
### Instruction: Show Vote History for a Post. ### Response:
SELECT v.Id, v.PostId AS "post_link", v.UserId AS "user_link", v.CreationDate, v.BountyAmount, v.VoteTypeId, vt.Name FROM Posts AS p JOIN Votes AS v ON (p.Id = v.PostId) JOIN VoteTypes AS vt ON (v.VoteTypeId = vt.Id) WHERE p.Id = @PostId AND v.VoteTypeId IN (2, 3) ORDER BY v.CreationDate DESC
### Instruction: what was the dosage of ezetimibe that was last prescribed to patient 82159 during their last hospital encounter? ### Response:
SELECT prescriptions.dose_val_rx FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 82159 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) AND prescriptions.drug = 'ezetimibe' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: Number of questions which get closed (per day, between dates). ### Response:
SELECT DATE(p.CreationDate), COUNT(p.ClosedDate) AS closed, COUNT(*) AS total, ROUND((COUNT(p.ClosedDate)) * 100.0 / (COUNT(p.Id)), 2) AS percentage FROM Posts AS p WHERE p.CreationDate >= '##Date1##' AND p.CreationDate <= '##Date2##' AND p.PostTypeId = 1 GROUP BY DATE(p.CreationDate) ORDER BY DATE(p.CreationDate)
### Instruction: Who are the teachers of upper-level classes ? ### Response:
SELECT DISTINCT instructor.name FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN offering_instructor ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN instructor ON offering_instructor.instructor_id = instructor.instructor_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE program_course.category LIKE '%ULCS%'
### Instruction: Which of your posts have been downvoted?. Lists posts (including both questions and answers) owned by the given user that have been downvoted at least once, sorted by number of downvotes in descending order. ### Response:
SELECT P.Id AS "post_link", P.CreationDate, COUNT(*) AS DownVotes FROM Posts AS P JOIN Votes AS V ON P.Id = V.PostId WHERE P.OwnerUserId = '##UserId:int##' AND V.VoteTypeId = 3 GROUP BY P.Id, P.CreationDate ORDER BY COUNT(*) DESC
### Instruction: whats the last height of patient 013-33898 this month? ### Response:
SELECT patient.admissionheight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '013-33898') AND NOT patient.admissionheight IS NULL AND DATETIME(patient.unitadmittime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') ORDER BY patient.unitadmittime DESC LIMIT 1
### Instruction: tell me what the top four most common output events during the previous year were. ### Response:
SELECT d_items.label FROM d_items WHERE d_items.itemid IN (SELECT t1.itemid FROM (SELECT outputevents.itemid, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM outputevents WHERE DATETIME(outputevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') GROUP BY outputevents.itemid) AS t1 WHERE t1.c1 <= 4)
### Instruction: Is there an CHEM 398 section that is not on Monday next semester ? ### Response:
SELECT DISTINCT course_offering.section_number FROM course, course_offering, semester WHERE course_offering.monday = 'N' AND course.course_id = course_offering.course_id AND course.department = 'CHEM' AND course.number = 398 AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: is there a microbiology test result in this month for patient 13054's sputum? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 13054) AND microbiologyevents.spec_type_desc = 'sputum' AND DATETIME(microbiologyevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month')
### Instruction: how many times patient 13782 has received a lymphocytes, percent test in 2102? ### Response:
SELECT COUNT(*) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'lymphocytes, percent') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 13782) AND STRFTIME('%y', labevents.charttime) = '2102'