instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: calculate how many drugs patient 015-94586 is prescribed in 06/2101. ### 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 = '015-94586')) AND STRFTIME('%y-%m', medication.drugstarttime) = '2101-06'
### Instruction: did patient 030-6441 have a wound care procedure at other hospitals? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.uniquepid = '030-6441' AND patient.hospitalid <> (SELECT DISTINCT patient.hospitalid FROM patient WHERE patient.uniquepid = '030-6441' AND patient.hospitaldischargetime IS NULL)) AND treatment.treatmentname = 'wound care'
### Instruction: count the number of patients whose discharge location is disch-tran to psych hosp and primary disease is coronary artery disease\coronary artery bypass graft; myomectomy/sda? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic WHERE demographic.discharge_location = "DISCH-TRAN TO PSYCH HOSP" AND demographic.diagnosis = "CORONARY ARTERY DISEASE\CORONARY ARTERY BYPASS GRAFT; MYOMECTOMY/SDA"
### Instruction: give me the number of patients whose primary disease is coronary artery disease\coronary artery bypass graft; myomectomy/sda and lab test fluid is pleural? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE demographic.diagnosis = "CORONARY ARTERY DISEASE\CORONARY ARTERY BYPASS GRAFT; MYOMECTOMY/SDA" AND lab.fluid = "Pleural"
### Instruction: Information on tags (included deleted ones). ### Response:
SELECT e.Body, w.Body, e.Id, e.CreationDate, e.LastEditorUserId AS "user_link", e.LastEditDate, w.Id, w.CreationDate, w.LastEditorUserId AS "user_link", w.LastEditDate FROM Tags AS t LEFT OUTER JOIN Posts AS e ON t.ExcerptPostId = e.Id LEFT OUTER JOIN Posts AS w ON t.WikiPostId = w.Id WHERE t.TagName = '##tagname:string##'
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, give me the comparison about the sum of manager_id over the hire_date bin hire_date by time by a bar chart, list by the Y in asc. ### Response:
SELECT HIRE_DATE, SUM(MANAGER_ID) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY SUM(MANAGER_ID)
### Instruction: tell me the diagnosis cost of duodenitis w hmrhg in a patient? ### 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 = 'duodenitis w hmrhg'))
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, a bar chart shows the distribution of hire_date and the sum of department_id bin hire_date by weekday, and show y axis in ascending order. ### Response:
SELECT HIRE_DATE, SUM(DEPARTMENT_ID) FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY SUM(DEPARTMENT_ID)
### Instruction: have there been any microbiological catheter tip-iv tests for patient 76332 in 12/2105? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 76332) AND microbiologyevents.spec_type_desc = 'catheter tip-iv' AND STRFTIME('%y-%m', microbiologyevents.charttime) = '2105-12'
### Instruction: all NW and UA flights with stopovers in DENVER ### Response:
SELECT DISTINCT flight.flight_id FROM airport_service, city, flight, flight_stop WHERE ((flight.airline_code = 'NW') OR (flight.airline_code = 'UA')) AND city.city_code = airport_service.city_code AND city.city_name = 'DENVER' AND flight_stop.stop_airport = airport_service.airport_code AND flight.flight_id = flight_stop.flight_id
### Instruction: has patient 006-124193 underwent any lab test in 12/2105? ### Response:
SELECT COUNT(*) > 0 FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-124193')) AND STRFTIME('%y-%m', lab.labresulttime) = '2105-12'
### Instruction: What 's the easiest ULCS class ? ### 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: Name the ULCS course that is easy . ### 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: Orphaned possible low quality, low hanging fruit questions. ### Response:
SELECT Posts.Id AS "post_link", Posts.Title, Posts.LastActivityDate, Posts.Tags FROM Posts JOIN Users ON Posts.OwnerUserId = Users.Id WHERE Posts.Score = 0 AND Posts.DeletionDate IS NULL AND Posts.ClosedDate IS NULL AND Posts.AnswerCount > 5 AND Posts.ParentId IS NULL AND Posts.AcceptedAnswerId IS NULL AND Users.LastAccessDate < DATEADD(year, -10, GETDATE())
### Instruction: Posts in danger of automatic deletion. ### Response:
SELECT Title, Id AS "post_link", DATEDIFF(day, CreationDate, GETDATE()) AS Age, Score, CommentCount FROM Posts AS p WHERE PostTypeId = 1 AND DATEDIFF(day, CreationDate, GETDATE()) > 300 AND ((Score <= 0) OR (Score <= 1 AND OwnerUserId IS NULL)) AND NOT EXISTS(SELECT 1 FROM Posts AS q WHERE p.Id = q.ParentId) ORDER BY DATEDIFF(day, CreationDate, GETDATE())
### Instruction: count how many times patient 26469 had received a lab urobilinogen test since 6 years ago. ### Response:
SELECT COUNT(*) FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'urobilinogen') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 26469) AND DATETIME(labevents.charttime) >= DATETIME(CURRENT_TIME(), '-6 year')
### Instruction: fraction of nonpositively-scored Qs per tag. ### Response:
SELECT Tags.TagName, CAST(SUM(CASE WHEN Posts.Score < 1 THEN 1 ELSE 0 END) AS FLOAT) / CAST(COUNT(*) AS FLOAT) AS fraction_of_nonpositive_Qs FROM (PostTags INNER JOIN Tags ON PostTags.TagId = Tags.Id) INNER JOIN Posts ON Posts.Id = PostTags.PostId WHERE Tags.Count > 9 GROUP BY Tags.TagName ORDER BY fraction_of_nonpositive_Qs DESC, TagName
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, find hire_date and the average of manager_id bin hire_date by weekday, and visualize them by a bar chart. ### Response:
SELECT HIRE_DATE, AVG(MANAGER_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: My suggested edit votes that got overruled. Provides links to the suggested edits that you voted on, where the outcome went against your vote. ### Response:
SELECT edit.PostId, edit.Id AS "suggested_edit_link" FROM SuggestedEditVotes AS vote, SuggestedEdits AS edit WHERE vote.UserId = @UserId AND vote.SuggestedEditId = edit.Id AND (NOT edit.ApprovalDate IS NULL AND vote.VoteTypeId = 3 OR NOT edit.RejectionDate IS NULL AND vote.VoteTypeId = 2)
### Instruction: when was the first time during the current hospital encounter patient 017-16041 was prescribed a medication? ### 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 = '017-16041' AND patient.hospitaldischargetime IS NULL)) ORDER BY medication.drugstarttime LIMIT 1
### Instruction: what was the last height of patient 006-1634 in the previous month. ### Response:
SELECT patient.admissionheight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-1634') AND NOT patient.admissionheight IS NULL AND DATETIME(patient.unitadmittime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY patient.unitadmittime DESC LIMIT 1
### Instruction: Most upvoted questions by tag. ### Response:
SELECT COUNT(v.PostId), v.PostId AS "post_link", p.Tags, TIME_TO_STR(p.CreationDate, '%Year') FROM Posts AS P JOIN Votes AS V ON p.Id = v.PostId WHERE PostTypeId = 1 AND VoteTypeId = 2 GROUP BY p.Title, p.Body, v.PostId, p.Tags, TIME_TO_STR(p.CreationDate, '%Year') ORDER BY COUNT(v.PostId) DESC LIMIT 12
### Instruction: How many patients had aortic insufficiency/re-do sternotomy, aortic valve replacement had cnt intraart bld gas mon? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.diagnosis = "AORTIC INSUFFICIENCY\RE-DO STERNOTOMY; AORTIC VALVE REPLACEMENT " AND procedures.short_title = "Cnt intraart bld gas mon"
### Instruction: had patient 002-13750 been diagnosed with any illness since 4 years 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 = '002-13750')) AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-4 year')
### Instruction: when did patient 10855 receive a prescription for the last time since 11/2102, via tt route? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 10855) AND prescriptions.route = 'tt' AND STRFTIME('%y-%m', prescriptions.startdate) >= '2102-11' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, a line chart shows the trend of salary over hire_date , and could you list from high to low by the X? ### Response:
SELECT HIRE_DATE, SALARY FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY HIRE_DATE DESC
### Instruction: was patient 29971 given a rt/left heart card cath treatment? ### 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 = 29971)
### Instruction: how many days has it been since the last time patient 7112 stayed during the current hospital encounter in careunit micu? ### Response:
SELECT 1 * (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 = 7112 AND admissions.dischtime IS NULL) AND transfers.careunit = 'micu' ORDER BY transfers.intime DESC LIMIT 1
### Instruction: Unanswered questions tagged with google-maps for last 7 days. ### Response:
SELECT p.Id, p.Title, p.Tags, p.AcceptedAnswerId, p.Score, p.ViewCount, p.AnswerCount, p.CommentCount, p.ClosedDate FROM Posts AS p INNER JOIN PostTags AS pt ON p.Id = Pt.PostId INNER JOIN Tags AS t ON pt.TagId = t.Id WHERE t.TagName = 'google-maps' AND p.CreationDate >= DATEADD(Day, -7, GETDATE()) ORDER BY p.Score DESC
### Instruction: How am I ranked among those who have not asked a question?. ### Response:
SELECT (ROW_NUMBER() OVER (ORDER BY Reputation DESC)), u.Id AS "user_link", u.Reputation FROM Users AS u WHERE (SELECT COUNT(p.Id) FROM Posts AS p WHERE p.OwnerUserId = u.Id AND p.PostTypeId = 1) = 0 AND (SELECT COUNT(p.Id) FROM Posts AS p WHERE p.OwnerUserId = u.Id AND p.PostTypeId = 2) > 0 AND u.Reputation > 101
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, give me the comparison about the sum of employee_id over the hire_date bin hire_date by time by a bar chart. ### Response:
SELECT HIRE_DATE, SUM(EMPLOYEE_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: did patient 006-83264 in 2105 get an total protein lab test? ### Response:
SELECT COUNT(*) > 0 FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-83264')) AND lab.labname = 'total protein' AND STRFTIME('%y', lab.labresulttime) = '2105'
### Instruction: What have I voted by tag?. ### Response:
SELECT DISTINCT Posts.Title, Posts.Body, Posts.Id, Posts.Score, Posts.OwnerDisplayName, Posts.Tags, TagName FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.Id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id AND VoteTypeId = 2 WHERE TagName = 'backbone.js' AND Score > 10 AND Score < 25 ORDER BY Score 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, return a bar chart about the distribution of job_id and the amount of job_id , and group by attribute job_id. ### Response:
SELECT JOB_ID, COUNT(JOB_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 GROUP BY JOB_ID
### Instruction: Who has coauthored with dan suciu ? ### Response:
SELECT DISTINCT AUTHOR_1.authorid FROM author AS AUTHOR_0, author AS AUTHOR_1, writes AS WRITES_0, writes AS WRITES_1 WHERE AUTHOR_0.authorname = 'dan suciu' AND WRITES_0.authorid = AUTHOR_0.authorid AND WRITES_1.authorid = AUTHOR_1.authorid AND WRITES_1.paperid = WRITES_0.paperid
### Instruction: What's the least mpg-UK combined when the mpg-UK urban is 25.4, the L/100km extra urban is less than 6.9 and the L/100km urban is more than 11.1? ### Response:
SELECT MIN(mpg_uk_combined) FROM table_name_42 WHERE mpg_uk_urban__cold_ = 25.4 AND l_100km_extra_urban < 6.9 AND l_100km_urban__cold_ > 11.1
### Instruction: Question length and score (I don't know SQL...). ### Response:
WITH Keyed AS (SELECT CAST(Posts.Score AS FLOAT) AS Score, POWER(ROUND(SQRT(LENGTH(Body)), 0), 2) AS PostLength FROM Posts WHERE PostTypeId = 1), Sized AS (SELECT PostLength, AVG(Score) AS MeanScore, COUNT(Score) AS ClusterSize FROM Keyed GROUP BY PostLength) SELECT PostLength, MeanScore, ClusterSize FROM Sized WHERE ClusterSize > 100 ORDER BY PostLength
### Instruction: Try to answer these questions, to increase your tag score. ### Response:
WITH TagScores AS (SELECT PostTags.TagId, SUM(5 - 2 * Votes.VoteTypeId) AS Score FROM Posts, Votes, PostTags WHERE Posts.ParentId = PostTags.PostId AND Votes.PostId = Posts.Id AND Votes.VoteTypeId BETWEEN 2 AND 3 AND Posts.OwnerUserId = @UserId AND Posts.CommunityOwnedDate IS NULL GROUP BY PostTags.TagId) SELECT * FROM TagScores
### Instruction: are there any results of the microbiological test for patient 17638's blood (cmv ab) since 4 years ago? ### Response:
SELECT COUNT(*) > 0 FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17638) AND microbiologyevents.spec_type_desc = 'blood (cmv ab)' AND DATETIME(microbiologyevents.charttime) >= DATETIME(CURRENT_TIME(), '-4 year')
### Instruction: Number of Post per Day for one Tag. ### Response:
SELECT CAST(FLOOR(CAST(CreationDate AS FLOAT)) AS DATETIME), COUNT(*) AS questions FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.Id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId WHERE Tags.TagName = '##TagName##' GROUP BY CAST(FLOOR(CAST(CreationDate AS FLOAT)) AS DATETIME) ORDER BY CAST(FLOOR(CAST(CreationDate AS FLOAT)) AS DATETIME)
### Instruction: has patient 59049 received a glucose test since 01/2105? ### Response:
SELECT COUNT(*) > 0 FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'glucose') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 59049) AND STRFTIME('%y-%m', labevents.charttime) >= '2105-01'
### Instruction: what was the name of the specimen test that patient 65582 had last received in this month? ### Response:
SELECT microbiologyevents.spec_type_desc FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 65582) AND DATETIME(microbiologyevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: For CEE 650 next semester , are there any sections 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 = 'CEE' AND course.number = 650 AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: What company has more than 195.34 billion in sales, ranked greater than 7, more than 11.29 billion in profits, and a market value greater than 198.14 billion? ### Response:
SELECT "Company" FROM table_43911 WHERE "Sales (billion $)" > '195.34' AND "Rank" > '7' AND "Profits (billion $)" > '11.29' AND "Market Value (billion $)" > '198.14'
### Instruction: First & Last Date for Posts Bumped N Times by Community User. ### Response:
SELECT P.Id, B.BumpCount, B.FirstBump, B.LastBump, P.Title FROM Posts AS P JOIN (SELECT PostId, COUNT(*) AS BumpCount, MIN(CreationDate) AS FirstBump, MAX(CreationDate) AS LastBump FROM PostHistory WHERE PostHistoryTypeId = 50 GROUP BY PostId HAVING COUNT(*) > 2) AS B ON P.Id = B.PostId ORDER BY B.BumpCount, P.Id
### Instruction: the previous year, how many patients were prescribed with propofol 1000 mg/100 ml? ### Response:
SELECT COUNT(DISTINCT patient.uniquepid) FROM patient WHERE patient.patientunitstayid IN (SELECT medication.patientunitstayid FROM medication WHERE medication.drugname = 'propofol 1000 mg/100 ml' AND DATETIME(medication.drugstarttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year'))
### Instruction: Tell me the number of patients who are taking base type drug prescription and have diagnoses of twin birth, mate liveborn, born in hospital, delivered by cesarean section. ### 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.short_title = "Twin-mate lb-in hos w cs" AND prescriptions.drug_type = "BASE"
### Instruction: highest rated answers since a date. ### Response:
SELECT A.* FROM Posts AS A INNER JOIN Posts AS Q ON A.ParentId = Q.Id INNER JOIN PostTags AS PT ON Q.Id = PT.PostId INNER JOIN Tags AS T ON PT.TagId = T.Id WHERE A.PostTypeId = 2 AND Q.PostTypeId = 1 AND A.Score >= 80 AND A.CreationDate >= CAST('2017-10-01' AS DATETIME) AND T.TagName = 'r' ORDER BY A.Score DESC
### Instruction: Row_Number | Find the first occurrence in a series. ### Response:
SELECT U.DisplayName, COALESCE(P.Title, 'Unknown') AS "TITLE", CASE WHEN (ROW_NUMBER() OVER (PARTITION BY U.Id ORDER BY P.CreationDate DESC)) = 1 THEN 'Y' ELSE 'N' END AS "FIRST POST?", p.CreationDate FROM Posts AS P INNER JOIN Users AS U ON P.OwnerUserId = U.Id AND P.OwnerUserId IN (610455, 174910)
### Instruction: give me the number of patients whose ethnicity is hispanic/latino - puerto rican and drug name is sulfamethoxazole-trimethoprim? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE demographic.ethnicity = "HISPANIC/LATINO - PUERTO RICAN" AND prescriptions.drug = "Sulfamethoxazole-Trimethoprim"
### Instruction: Questions with multiple bounties by any users. ### Response:
SELECT questions.Id AS "post_link", 'site://posts/' + CAST(questions.Id AS TEXT) + '/timeline|timeline' AS "Timeline link", COUNT(*) AS "Number of bounties", SUM(Votes.BountyAmount) AS "Total bounty amount" FROM Posts AS questions LEFT JOIN Votes AS votes ON Votes.PostId = questions.Id WHERE Votes.VoteTypeId = 8 GROUP BY questions.Id HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC
### Instruction: Which Spring classes are ECON upper level ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, program_course, semester WHERE course.course_id = course_offering.course_id AND course.department = 'ECON' AND program_course.category LIKE '%ULCS%' AND program_course.course_id = course.course_id AND semester.semester = 'Spring' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: Give me the number of patients diagnosed with type 1 diabetes with renal manifestations that were not stated as uncontrolled who had vasopressor infusion. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE diagnoses.short_title = "DMI renl nt st uncntrld" AND procedures.short_title = "Infusion of vasopressor"
### Instruction: what test did patient 3403 go through for the first time since 04/2105? ### 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 = 3403) AND STRFTIME('%y-%m', labevents.charttime) >= '2105-04' ORDER BY labevents.charttime LIMIT 1)
### Instruction: calculate the number of patients who had had a cd3 cells, percent lab test in this year. ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT labevents.hadm_id FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'cd3 cells, percent') AND DATETIME(labevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year'))
### Instruction: when did patient 9294 receive a prescription for nadolol in this month first? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 9294) AND prescriptions.drug = 'nadolol' AND DATETIME(prescriptions.startdate, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') ORDER BY prescriptions.startdate LIMIT 1
### Instruction: what are commonly cited papers by tom mitchell and oren etzioni ? ### Response:
SELECT DISTINCT author.authorname, cite.citedpaperid, COUNT(cite.citedpaperid) FROM author, cite, paper, writes WHERE author.authorname IN ('tom mitchell', 'oren etzioni') AND paper.paperid = cite.citedpaperid AND writes.authorid = author.authorid AND writes.paperid = paper.paperid GROUP BY cite.citedpaperid, author.authorname ORDER BY COUNT(cite.citedpaperid) DESC
### Instruction: uses of the word 'qua'. ### Response:
SELECT UserId, Text, Id, 'comment' FROM Comments WHERE Text LIKE @match UNION SELECT UserId, Text, Id, 'posthistory text' FROM PostHistory WHERE Text LIKE @match UNION SELECT UserId, Comment, Id, 'posthistory comment' FROM PostHistory WHERE Comment LIKE @match UNION SELECT OwnerUserId, Text, Id, 'suggestededit text' FROM SuggestedEdits WHERE Text LIKE @match UNION SELECT OwnerUserId, Title, Id, 'suggestededit title' FROM SuggestedEdits WHERE Title LIKE @match
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, find hire_date and the average of department_id bin hire_date by time, and visualize them by a bar chart. ### Response:
SELECT HIRE_DATE, AVG(DEPARTMENT_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: count the number of patients whose diagnoses long title is venous (peripheral) insufficiency, unspecified and drug route is iv? ### 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 = "Venous (peripheral) insufficiency, unspecified" AND prescriptions.route = "IV"
### Instruction: what is the name of the drug patient 013-28507 was last prescribed in this hospital encounter? ### 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 = '013-28507' AND patient.hospitaldischargetime IS NULL)) ORDER BY medication.drugstarttime DESC LIMIT 1
### Instruction: had patient 021-114154 had any allergies until 56 months ago? ### 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 = '021-114154')) AND DATETIME(allergy.allergytime) <= DATETIME(CURRENT_TIME(), '-56 month')
### Instruction: count the number of patients whose diagnoses long title is fall from other slipping, tripping, or stumbling and drug type is additive? ### 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 = "Fall from other slipping, tripping, or stumbling" AND prescriptions.drug_type = "ADDITIVE"
### Instruction: Questions with more than n answers. ### Response:
SELECT q.Id, q.Title, q.Body, q.AnswerCount, a.Id, a.Body, q.CreationDate, a.CreationDate, q.ClosedDate, a.ClosedDate, q.ViewCount, q.OwnerUserId, a.OwnerUserId, q.FavoriteCount FROM Posts AS q INNER JOIN Posts AS a ON a.ParentId = q.Id WHERE q.PostTypeId = 1 AND a.PostTypeId = 2 AND q.AnswerCount >= 10
### Instruction: Which Other classes are offered during the Winter semester ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN semester ON semester.semester_id = course_offering.semester INNER JOIN program_course ON program_course.course_id = course_offering.course_id WHERE program_course.category LIKE '%Other%' AND semester.semester = 'Winter' AND semester.year = 2017
### Instruction: Which 300 -level courses are presented after this semester ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, semester WHERE course.course_id = course_offering.course_id AND course.department = 'EECS' AND course.number BETWEEN 300 AND 300 + 100 AND semester.semester = 'FA' AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: How to list posts which have a particular tag but didn't have it when originally asked?. https://meta.stackexchange.com/questions/355412 ### Response:
SELECT DISTINCT PostId AS "post_link" FROM PostHistory AS ph WHERE PostHistoryTypeId = 6 AND Text LIKE CONCAT('%<', '##tagname:string##', '>%') AND NOT EXISTS(SELECT PostId FROM PostHistory WHERE PostHistoryTypeId = 3 AND PostId = ph.PostId AND Text LIKE CONCAT('%<', '##tagname:string##', '>%'))
### Instruction: Does Prof. Liliana Naydan always set exams for her classes ? ### Response:
SELECT COUNT(*) = 0 FROM course INNER JOIN course_offering ON course.course_id = course_offering.course_id INNER JOIN offering_instructor ON offering_instructor.offering_id = course_offering.offering_id INNER JOIN instructor ON offering_instructor.instructor_id = instructor.instructor_id WHERE course.has_exams = 'N' AND instructor.name LIKE '%Liliana Naydan%'
### Instruction: Find the name and address of the customers who have both New and Pending orders. ### Response:
SELECT T1.customer_name, T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "New" INTERSECT SELECT T1.customer_name, T1.customer_address FROM customers AS T1 JOIN customer_orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status_code = "Pending"
### Instruction: A bar chart for what are the number of the dates of birth of entrepreneurs with investor 'Simon Woodroffe' or 'Peter Jones'?, and I want to rank total number in ascending order. ### Response:
SELECT Date_of_Birth, COUNT(Date_of_Birth) FROM entrepreneur AS T1 JOIN people AS T2 ON T1.People_ID = T2.People_ID WHERE T1.Investor = "Simon Woodroffe" OR T1.Investor = "Peter Jones" ORDER BY COUNT(Date_of_Birth)
### Instruction: What is the sum of number of bearers in 2009 for a rank above 1, a type of patronymic, an etymology meaning son of Christian, and the number of bearers in 1971 greater than 45.984? ### Response:
SELECT SUM(number_of_bearers_2009) FROM table_name_3 WHERE rank > 1 AND type = "patronymic" AND etymology = "son of christian" AND number_of_bearers_1971 > 45.984
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, find hire_date and the sum of department_id bin hire_date by weekday, and visualize them by a bar chart. ### Response:
SELECT HIRE_DATE, SUM(DEPARTMENT_ID) FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: Is there going to be an Chinese Art and Religion colloquium this year ? ### Response:
SELECT COUNT(*) > 0 FROM course, course_offering, semester WHERE (course.description LIKE '%colloquium%' OR course.name LIKE '%colloquium%') AND (course.description LIKE '%Chinese Art and Religion%' OR course.name LIKE '%Chinese Art and Religion%') AND course.course_id = course_offering.course_id AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: tell me the top five most common output events that were in this year? ### 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', '-0 year') GROUP BY outputevents.itemid) AS t1 WHERE t1.c1 <= 5)
### Instruction: Which Place has a Country of united states, and Money ($) larger than 145,000, and a To par of 2, and a Score of 70-66-73-69=278? ### Response:
SELECT "Place" FROM table_47467 WHERE "Country" = 'united states' AND "Money ( $ )" > '145,000' AND "To par" = '–2' AND "Score" = '70-66-73-69=278'
### Instruction: how much phenylephrine is prescribed to patient 9983 first time until 36 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 = 9983) AND prescriptions.drug = 'phenylephrine' AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-36 month') ORDER BY prescriptions.startdate 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 , display by the X from low to high. ### 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
### Instruction: when was the first time that patient 64538 was prescribed a medication until 11/2103 via oral? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 64538) AND prescriptions.route = 'oral' AND STRFTIME('%y-%m', prescriptions.startdate) <= '2103-11' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: Top Askers (with average score). Shows the top 50 askers by question count. ### Response:
SELECT OwnerUserId AS "user_link", COUNT(*) AS PostCount, SUM(Score) AS TotalScore, AVG(Score) AS AverageScore FROM Posts WHERE PostTypeId = '##PostTypeId?1##' AND OwnerUserId != 1 AND Tags LIKE '##TagName?%%##' GROUP BY OwnerUserId HAVING COUNT(*) > '##MinNrPosts?10##' ORDER BY AVG(Score) LIMIT 10000
### Instruction: how many days have passed since patient 8888 last stayed in this hospital encounter in the careunit tsicu? ### Response:
SELECT 1 * (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 = 8888 AND admissions.dischtime IS NULL) AND transfers.careunit = 'tsicu' ORDER BY transfers.intime DESC LIMIT 1
### Instruction: what was the maximum value of patient 28484's wbc count on their first hospital visit? ### Response:
SELECT MAX(labevents.valuenum) FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 28484 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'wbc count')
### Instruction: Meta Stack Overflow [featured] history. latest first ### Response:
SELECT Posts.Score, Posts.Id AS "post_link", Posts.CreationDate, Posts.LastEditDate, PostHistory.CreationDate FROM PostHistory JOIN Posts ON PostHistory.PostId = Posts.Id WHERE PostHistory.PostHistoryTypeId = 6 AND PostHistory.Text LIKE '%<featured>%' GROUP BY Posts.Score, Posts.Id, Posts.CreationDate, Posts.LastEditDate, PostHistory.CreationDate ORDER BY PostHistory.CreationDate DESC
### Instruction: count the number of drugs that have been prescribed patient 002-77945 until 3 years ago. ### 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 = '002-77945')) AND DATETIME(medication.drugstarttime) <= DATETIME(CURRENT_TIME(), '-3 year')
### Instruction: list the minimum monthly records of abscess - head and neck - mastoiditis since 2105? ### Response:
SELECT MIN(t1.c1) FROM (SELECT COUNT(DISTINCT diagnosis.patientunitstayid) AS c1 FROM diagnosis WHERE diagnosis.diagnosisname = 'abscess - head and neck - mastoiditis' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2105' GROUP BY STRFTIME('%y-%m', diagnosis.diagnosistime)) AS t1
### Instruction: has patient 14054 had any lab tests performed for eosinophils since 2105? ### Response:
SELECT COUNT(*) > 0 FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'eosinophils') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 14054) AND STRFTIME('%y', labevents.charttime) >= '2105'
### Instruction: what was the first time patient 96774 was prescribed a medication using an sc route until 04/2102? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 96774) AND prescriptions.route = 'sc' AND STRFTIME('%y-%m', prescriptions.startdate) <= '2102-04' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: Up/user and down/user ratio between a certain range of users. ### Response:
SELECT COUNT(0) AS NumUsers, SUM(UpVotes) / COUNT(0) AS AvrUpVotes, SUM(DownVotes) / COUNT(0) AS AvrDownVotes, (SUM(UpVotes) / COUNT(0)) / (SUM(DownVotes) / COUNT(0)) AS Ratio FROM Users WHERE Reputation >= '##LowBoundy:int?1000##' AND Reputation <= '##HighBoundry:int?10000##'
### Instruction: count the number of patients whose days of hospital stay is greater than 17 and diagnoses long title is diabetes with renal manifestations, type i [juvenile type], not stated as uncontrolled? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.days_stay > "17" AND diagnoses.long_title = "Diabetes with renal manifestations, type I [juvenile type], not stated as uncontrolled"
### Instruction: was there an oxygen lab test performed on patient 25763 since 90 months ago? ### Response:
SELECT COUNT(*) > 0 FROM labevents WHERE labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'oxygen') AND labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25763) AND DATETIME(labevents.charttime) >= DATETIME(CURRENT_TIME(), '-90 month')
### Instruction: Overall Closed Status of my Questions. What percentage of my questions are closed? ### Response:
SELECT COUNT(Id) AS "All", SUM(CASE WHEN ClosedDate IS NULL THEN 1 ELSE 0 END) AS "Open", SUM(CASE WHEN NOT ClosedDate IS NULL THEN 1 ELSE 0 END) AS "Closed", SUM(CASE WHEN ClosedDate IS NULL THEN 1 ELSE 0 END) / CAST(COUNT(Id) AS FLOAT) AS "PercentOpen" FROM Posts WHERE PostTypeId = 1 AND OwnerUserId = '##UserId##'
### Instruction: until 45 months ago, when was the last time that carvedilol was prescribed to patient 5905? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 5905) AND prescriptions.drug = 'carvedilol' AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-45 month') ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: and what was the first time patient 71192 was prescribed medication using the lock route in 07/2103? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 71192) AND prescriptions.route = 'lock' AND STRFTIME('%y-%m', prescriptions.startdate) = '2103-07' ORDER BY prescriptions.startdate LIMIT 1
### Instruction: what was the total amount of output patient 92846 had in the previous day? ### 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 = 92846)) AND DATETIME(outputevents.charttime, 'start of day') = DATETIME(CURRENT_TIME(), 'start of day', '-1 day')
### Instruction: renal disease: urine dipstick 4+ protein, serum creatinine is greater than or equal to 1.4 mg / dl ( female ) or is greater than or equal to 1.5 mg / dl ( male ) or currently receiving dialysis ### Response:
SELECT * FROM table_dev_21 WHERE renal_disease = 1 OR (serum_creatinine >= 1.4 AND gender = 'female') OR (serum_creatinine >= 1.5 AND gender = 'male') OR dialysis = 1
### Instruction: what is the average daily number of patients who have had rash, infectious since 1 year ago? ### Response:
SELECT AVG(t1.c1) FROM (SELECT COUNT(DISTINCT diagnosis.patientunitstayid) AS c1 FROM diagnosis WHERE diagnosis.diagnosisname = 'rash, infectious' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-1 year') GROUP BY STRFTIME('%y-%m-%d', diagnosis.diagnosistime)) AS t1
### Instruction: For those employees whose salary is in the range of 8000 and 12000 and commission is not null or department number does not equal to 40, for salary, hire_date, visualize the trend, could you rank x-axis from high to low order? ### Response:
SELECT HIRE_DATE, SALARY FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40 ORDER BY HIRE_DATE DESC
### Instruction: This year , will there be an Nutritional Epidemiology lab ? ### Response:
SELECT COUNT(*) > 0 FROM course, course_offering, semester WHERE (course.description LIKE '%lab%' OR course.name LIKE '%lab%') AND (course.description LIKE '%Nutritional Epidemiology%' OR course.name LIKE '%Nutritional Epidemiology%') AND course.course_id = course_offering.course_id AND semester.semester_id = course_offering.semester AND semester.year = 2016
### Instruction: was any medicine prescribed since 2 years ago for patient 022-127032? ### 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 = '022-127032')) AND DATETIME(medication.drugstarttime) >= DATETIME(CURRENT_TIME(), '-2 year')
### Instruction: View percentiles for bountied questions. ### Response:
WITH BountiedPosts AS (SELECT p.* FROM Posts AS p JOIN Votes AS v ON v.PostId = p.Id AND v.VoteTypeId = 8 WHERE p.Score >= 0 AND ClosedDate IS NULL), Percentiles AS (SELECT NTILE(100) OVER (ORDER BY ViewCount) AS Percentile, ViewCount FROM BountiedPosts) SELECT MIN(ViewCount) AS NumberOfViews, Percentile FROM Percentiles GROUP BY Percentile ORDER BY Percentile
### Instruction: has patient 73913 been diagnosed with hyposmolality? ### 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 = 'hyposmolality') AND diagnoses_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 73913)