instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: Votes per day between creation and last access. ### Response:
SELECT DisplayName, CreationDate, UpVotes + DownVotes AS totalVotes, DATEDIFF(DAY, CreationDate, LastAccessDate) AS "Days active", (UpVotes + DownVotes) / (CASE WHEN DATEDIFF(DAY, CreationDate, LastAccessDate) = 0 THEN 1 ELSE DATEDIFF(DAY, CreationDate, LastAccessDate) END) AS "Votes per day" FROM Users WHERE Reputation >= 15 ORDER BY 5 DESC
### Instruction: By whom is BIOLOGY 281 taught ? ### Response:
SELECT DISTINCT instructor.name FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.department = 'BIOLOGY' AND course.number = 281 AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: Show the number of start dates of all the apartment bookings made by guests with gender code 'Female' for each year with a bar chart, and show by the the number of booking start date in descending. ### Response:
SELECT booking_start_date, COUNT(booking_start_date) FROM Apartment_Bookings AS T1 JOIN Guests AS T2 ON T1.guest_id = T2.guest_id WHERE T2.gender_code = "Female" ORDER BY COUNT(booking_start_date) DESC
### Instruction: is there an airport LIMOUSINE at the ATLANTA airport ### Response:
SELECT DISTINCT ground_service.transport_type FROM airport, airport_service, city, ground_service WHERE airport.airport_code = airport_service.airport_code AND city.city_code = airport_service.city_code AND city.city_name = 'ATLANTA' AND ground_service.airport_code = airport.airport_code AND ground_service.transport_type = 'LIMOUSINE'
### Instruction: Where do users dominate comments?. ### Response:
SELECT c.UserId AS "user_link", COUNT(DISTINCT p.Id) AS postsCount FROM Posts AS p INNER JOIN Comments AS c ON p.Id = c.PostId WHERE p.CommentCount >= @commentcount AND CAST((SELECT COUNT(Id) FROM Comments WHERE PostId = p.Id AND UserId = c.UserId) AS FLOAT) >= @percentage * CAST(p.CommentCount AS FLOAT) GROUP BY c.UserId ORDER BY postsCount DESC
### Instruction: what is the number of patients whose diagnoses long title is congestive heart failure, unspecified and drug route is iv drip? ### 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 = "Congestive heart failure, unspecified" AND prescriptions.route = "IV DRIP"
### Instruction: Suggested edits voting compared to final result. ### Response:
SELECT p.Id AS Id, p.Id AS "post_link", se.Id AS "suggested_edit_link" FROM SuggestedEdits AS se INNER JOIN SuggestedEditVotes AS sev ON sev.SuggestedEditId = se.Id INNER JOIN Posts AS p ON p.Id = se.PostId WHERE sev.UserId = '##UserId##' AND NOT se.RejectionDate IS NULL AND sev.VoteTypeId = 2
### Instruction: Most Frequent Tags in Austin TX. ### Response:
SELECT t.TagName, COUNT(t.TagName) AS c FROM Posts AS p INNER JOIN PostTags AS ptags ON p.Id = ptags.PostId INNER JOIN Tags AS t ON ptags.TagId = t.Id INNER JOIN PostTypes AS pt ON p.PostTypeId = pt.Id INNER JOIN Users AS u ON p.OwnerUserId = u.Id WHERE pt.Name IN ('Answer', 'Question') AND u.Location LIKE '%Austin%' GROUP BY t.TagName ORDER BY c DESC
### Instruction: during the last year what was the last ward id of patient 99135? ### Response:
SELECT transfers.wardid FROM transfers WHERE transfers.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 99135) AND NOT transfers.wardid IS NULL AND DATETIME(transfers.intime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') ORDER BY transfers.intime DESC LIMIT 1
### Instruction: Questions with the given tag containing the given text (case insensitive). ### Response:
SELECT q.Id AS "post_link", q.Title, q.Tags, q.CreationDate, q.LastActivityDate FROM Posts AS q INNER JOIN PostTags AS pt ON q.Id = pt.PostId INNER JOIN Tags AS t ON t.Id = pt.TagId WHERE t.TagName = '##tagname:string?geometry##' AND (LOWER(q.Body) LIKE '%##text?volume##%') ORDER BY q.CreationDate DESC
### Instruction: Delay of answer after the question. ### Response:
WITH answered_cte AS (SELECT a.Id AS aid, DATEDIFF(day, q.CreationDate, CreationDate) AS Days FROM Posts AS q INNER JOIN Posts AS a ON a.ParentId = q.Id WHERE (q.PostTypeId = 1) AND (q.AnswerCount > 0) GROUP BY a.Id, q.CreationDate, a.CreationDate) SELECT Days, COUNT(aid) AS Count FROM answered_cte GROUP BY Days ORDER BY Days
### Instruction: The DUTCH 492 teacher , who is it ? ### Response:
SELECT DISTINCT instructor.name FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.department = 'DUTCH' AND course.number = 492 AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: how many hours has passed since the last time patient 025-44842 stayed in ward 925 on their current hospital visit? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', patient.unitadmittime)) FROM patient WHERE patient.uniquepid = '025-44842' AND patient.wardid = 925 AND patient.hospitaldischargetime IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1
### Instruction: provide the number of patients categorized under chemistry lab test who have been diagnosed with contusion of face, scalp, and neck except eye(s). ### 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.short_title = "Contusion face/scalp/nck" AND lab."CATEGORY" = "Chemistry"
### Instruction: Users with over 1000 Questions. ### Response:
SELECT U.Id AS "user_link", COUNT(Pt.Id) AS QUESTIONS FROM Users AS U, Posts AS P, PostHistory AS Ph, PostTypes AS Pt WHERE Pt.Id = Ph.PostHistoryTypeId AND U.Id = P.OwnerUserId AND P.Id = Ph.PostId AND Pt.Id = 1 GROUP BY U.Id HAVING COUNT(Pt.Id) > 1000 ORDER BY QUESTIONS DESC
### Instruction: Who wrote on the topic of Bacterial Wilt in 2016 ? ### Response:
SELECT DISTINCT writes.authorid FROM author, keyphrase, paper, paperkeyphrase, writes WHERE keyphrase.keyphrasename = 'Bacterial Wilt' AND paperkeyphrase.keyphraseid = keyphrase.keyphraseid AND paper.paperid = paperkeyphrase.paperid AND paper.year = 2016 AND writes.authorid = author.authorid AND writes.paperid = paper.paperid
### Instruction: how many hours is it since patient 030-44598 first stayed in the ward 1034 on their current hospital visit? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', patient.unitadmittime)) FROM patient WHERE patient.uniquepid = '030-44598' AND patient.wardid = 1034 AND patient.hospitaldischargetime IS NULL ORDER BY patient.unitadmittime LIMIT 1
### Instruction: has patient 006-80884 had any procedures undergone in 2105? ### Response:
SELECT COUNT(*) > 0 FROM treatment WHERE treatment.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-80884')) AND STRFTIME('%y', treatment.treatmenttime) = '2105'
### Instruction: is joe a vote tramp. ### Response:
WITH joe AS (SELECT u.CreationDate, u.DisplayName, u.DownVotes, u.UpVotes, DATEDIFF(DAY, u.CreationDate, GETDATE()) AS joe_days FROM dbo.Users AS u WHERE u.Id = 104717) SELECT *, joe.DownVotes / joe.joe_days AS dv_day, joe.UpVotes / joe.joe_days AS uv_day FROM joe
### Instruction: How many classes has Prof. Alan Gosman taken for 421 ? ### Response:
SELECT COUNT(*) FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND course.number = 421 AND instructor.name LIKE '%Alan Gosman%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: how many patients are admitted in location transfer from hosp/extram and procedured with endoscopic excision or destruction of lesion or tissue of esophagus? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.admission_location = "TRANSFER FROM HOSP/EXTRAM" AND procedures.long_title = "Endoscopic excision or destruction of lesion or tissue of esophagus"
### Instruction: what are the top three common diagnoses of patients of age 30s? ### Response:
SELECT t1.diagnosisname FROM (SELECT diagnosis.diagnosisname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM diagnosis WHERE diagnosis.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 30 AND 39) GROUP BY diagnosis.diagnosisname) AS t1 WHERE t1.c1 <= 3
### Instruction: Time between question and first answer. ### Response:
SELECT Hours, COUNT(*) FROM (SELECT CAST((JULIANDAY(MIN(a.CreationDate)) - JULIANDAY(q.CreationDate)) * 24.0 AS INT) AS Hours FROM Posts AS q INNER JOIN Posts AS a ON a.ParentId = q.Id WHERE q.CreationDate > '2019-01-01' GROUP BY q.Id, q.CreationDate) AS TEMP GROUP BY Hours ORDER BY Hours
### Instruction: how much does diagnosing accident in place nec costs? ### 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 = 'accident in place nec'))
### Instruction: plasma creatinine greater than 1.4 mg / dl in female or greater than 1.5 mg / dl in male , or 24 hour urine albumin excretion greater than 300 mg / dl ### Response:
SELECT * FROM table_dev_33 WHERE (plasma_creatinine > 1.4 AND gender = 'female') OR (plasma_creatinine > 1.5 AND gender = 'male') OR urine_albumin_excretion > 300
### Instruction: Questions not answered by me. ### Response:
SELECT p.Id, p.Id AS "post_link", p.Tags, p.CreationDate, p.ViewCount, p.OwnerUserId AS "user_link" FROM Posts AS p LEFT JOIN LATERAL (SELECT Id FROM Posts WHERE ParentId = p.Id AND OwnerUserId = 860099) AS a WHERE a.Id IS NULL AND p.PostTypeId = 1 AND p.Tags LIKE '%javascript%' ORDER BY p.Id LIMIT 100
### Instruction: provide the number of patients whose diagnoses short title is dmi keto nt st uncntrld and lab test category is blood gas? ### 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.short_title = "DMI keto nt st uncntrld" AND lab."CATEGORY" = "Blood Gas"
### Instruction: Average Answer Score for sapui5 / openui5 Questions. ### Response:
SELECT AVG(Answers.Score) FROM Posts AS Answers INNER JOIN Posts AS Questions ON Answers.ParentId = Questions.Id INNER JOIN PostTags ON Questions.Id = PostTags.PostId INNER JOIN Tags ON PostTags.TagId = Tags.Id WHERE Questions.PostTypeId = 1 AND Answers.PostTypeId = 2 AND (Tags.TagName = 'openui5' OR Tags.TagName = 'sapui5')
### Instruction: Of the Hist Urb Form courses , which are the ones which satisfy the MDE requirement ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course INNER JOIN area ON course.course_id = area.course_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE (area.area LIKE '%Hist Urb Form%' OR course.description LIKE '%Hist Urb Form%' OR course.name LIKE '%Hist Urb Form%') AND program_course.category LIKE '%MDE%'
### Instruction: show me the airlines with FIRST class flights ### Response:
SELECT DISTINCT airline.airline_code FROM airline, fare, fare_basis, flight, flight_fare WHERE fare_basis.class_type = 'FIRST' AND fare.fare_basis_code = fare_basis.fare_basis_code AND flight_fare.fare_id = fare.fare_id AND flight.airline_code = airline.airline_code AND flight.flight_id = flight_fare.flight_id
### Instruction: what was the name of the medication patient 26398 was prescribed the first time a month before? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 26398) AND DATETIME(prescriptions.startdate, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') ORDER BY prescriptions.startdate LIMIT 1
### Instruction: What is the number of each allergie type the girl named Lisa has? Show bar chart, and order from low to high by the y axis. ### Response:
SELECT AllergyType, COUNT(AllergyType) FROM Allergy_Type AS T1 JOIN Has_Allergy AS T2 ON T1.Allergy = T2.Allergy JOIN Student AS T3 ON T3.StuID = T2.StuID WHERE T3.Fname = "Lisa" GROUP BY AllergyType ORDER BY COUNT(AllergyType)
### Instruction: provide the number of patients whose year of birth is less than 2180 and procedure long title is initial insertion of transvenous leads [electrodes] into atrium and ventricle? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.dob_year < "2180" AND procedures.long_title = "Initial insertion of transvenous leads [electrodes] into atrium and ventricle"
### Instruction: Scala - Poland - Top Users. ### Response:
SELECT u.DisplayName, u.Reputation, u.WebsiteUrl, COUNT(*) AS ScalaAnswers FROM Users AS u, Posts AS p, Posts AS pp WHERE u.Id IN (SELECT Id FROM Users WHERE Location LIKE ('%Germany')) AND p.OwnerUserId = u.Id AND pp.Id = p.ParentId AND pp.Tags LIKE ('%<Scala>%') GROUP BY u.DisplayName, u.Reputation, u.WebsiteUrl ORDER BY ScalaAnswers DESC
### Instruction: Average Reputation per closed post. ### Response:
SELECT CloseReasonTypes.Name, Comment, AVG(Reputation) AS AverageReputation FROM (SELECT DISTINCT Users.Id, PostHistory.Comment, Users.Reputation FROM Users INNER JOIN Posts ON Users.Id = Posts.OwnerUserId INNER JOIN PostHistory ON Posts.Id = PostHistory.PostId WHERE PostHistory.PostHistoryTypeId = 10) AS Data INNER JOIN CloseReasonTypes ON CloseReasonTypes.Id = Comment GROUP BY Comment, CloseReasonTypes.Name
### Instruction: how many patients are of hispanico/latino - puerto rican ethnicity and have been prescribed the drug lidocaine-prilocaine? ### 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 = "Lidocaine-Prilocaine"
### Instruction: when did patient 64519 receive his or her last microbiology test until 09/2105? ### Response:
SELECT microbiologyevents.charttime FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 64519) AND STRFTIME('%y-%m', microbiologyevents.charttime) <= '2105-09' ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, find phone_number and commission_pct , and visualize them by a bar chart, and list from low to high by the x-axis. ### Response:
SELECT PHONE_NUMBER, COMMISSION_PCT FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY PHONE_NUMBER
### Instruction: has patient 009-5801 had surgery until 1 year ago? ### 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 = '009-5801')) AND DATETIME(treatment.treatmenttime) <= DATETIME(CURRENT_TIME(), '-1 year')
### Instruction: what is the number of patients whose primary disease is st elevated myocardial infarction\cardiac cath and procedure icd9 code is 9465? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.diagnosis = "ST ELEVATED MYOCARDIAL INFARCTION\CARDIAC CATH" AND procedures.icd9_code = "9465"
### Instruction: When critical altitude is sea level, what is the compression ration for a supercharger gear ratio of 7:1? ### Response:
SELECT "Compression ratio" FROM table_16551 WHERE "Critical altitude This is the highest altitude at which the engine can achieve its full continuous power rating. Above this altitude, power falls off with height as with a naturally aspirated engine . See Supercharger#Altitude effects for details." = 'sea level' AND "Supercharger gear ratio" = '7:1'
### Instruction: how many patients who are diagnosed with short title encephalopathy nos have been prescibed additive type of drug? ### 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 = "Encephalopathy NOS" AND prescriptions.drug_type = "ADDITIVE"
### Instruction: what is the total bag dose that until 51 months ago patient 27591 has been prescribed? ### Response:
SELECT SUM(prescriptions.dose_val_rx) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 27591) AND prescriptions.drug = 'bag' AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-51 month')
### Instruction: What is the venue of the competition '1994 FIFA World Cup qualification' hosted by 'Nanjing ( Jiangsu )'? ### Response:
SELECT T3.venue FROM city AS T1 JOIN hosting_city AS T2 ON T1.city_id = T2.host_city JOIN match AS T3 ON T2.match_id = T3.match_id WHERE T1.city = "Nanjing ( Jiangsu )" AND T3.competition = "1994 FIFA World Cup qualification"
### Instruction: Find number of Unanswered Questions on SO (questions with no answers at all). Counts the number of unanswered questions on SO, that are not community-wiki, not closed and have no accepted answer. ### Response:
SELECT q.Id, q.ViewCount, q.Title FROM Posts AS q WHERE (SELECT COUNT(*) FROM Posts AS a WHERE a.ParentId = q.Id) = 0 AND CommunityOwnedDate IS NULL AND ClosedDate IS NULL AND q.ParentId IS NULL AND AcceptedAnswerId IS NULL ORDER BY ViewCount DESC
### Instruction: What are the number of the payment dates for any payments that have an amount greater than 10 or were handled by a staff member with the first name Elsa?, and show by the total number in asc 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)
### 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 job_id and commission_pct , and rank in descending by the Y-axis please. ### Response:
SELECT JOB_ID, COMMISSION_PCT FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY COMMISSION_PCT DESC
### Instruction: has patient 031-13920 undergone any lab test since 2104? ### 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 = '031-13920')) AND STRFTIME('%y', lab.labresulttime) >= '2104'
### Instruction: What is the full name of the staff member who has rented a film to a customer with the first name April and the last name Burns? ### Response:
SELECT DISTINCT T1.first_name, T1.last_name FROM staff AS T1 JOIN rental AS T2 ON T1.staff_id = T2.staff_id JOIN customer AS T3 ON T2.customer_id = T3.customer_id WHERE T3.first_name = 'APRIL' AND T3.last_name = 'BURNS'
### Instruction: Which state spent the most revenue towards schools and whats the state average score ### Response:
SELECT T2.state, T3.average_scale_score FROM finrev_fed_key_17 AS T2 JOIN finrev_fed_17 AS T1 ON T1.state_code = T2.state_code JOIN ndecoreexcel_math_grade8 AS T3 ON T2.state = T3.state GROUP BY T2.state ORDER BY SUM(T1.t_fed_rev) DESC LIMIT 1
### Instruction: what is last weight of patient 013-29301 during their first hospital visit. ### Response:
SELECT patient.admissionweight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '013-29301' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1) AND NOT patient.admissionweight IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1
### Instruction: what's the top four most common output events until 2 years ago? ### 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) <= DATETIME(CURRENT_TIME(), '-2 year') GROUP BY outputevents.itemid) AS t1 WHERE t1.c1 <= 4)
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, find phone_number and commission_pct , and visualize them by a bar chart, list total number in descending order. ### Response:
SELECT PHONE_NUMBER, COMMISSION_PCT FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY COMMISSION_PCT DESC
### Instruction: What are the names of the products that have a color description of 'red' and the 'fast' characteristic? ### Response:
SELECT product_name FROM products AS t1 JOIN product_characteristics AS t2 ON t1.product_id = t2.product_id JOIN characteristics AS t3 ON t2.characteristic_id = t3.characteristic_id JOIN ref_colors AS t4 ON t1.color_code = t4.color_code WHERE t4.color_description = "red" AND t3.characteristic_name = "fast"
### Instruction: what is the number of times that gastroenterostomy nec is performed until 2 years ago? ### Response:
SELECT COUNT(*) FROM procedures_icd WHERE procedures_icd.icd9_code = (SELECT d_icd_procedures.icd9_code FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'gastroenterostomy nec') AND DATETIME(procedures_icd.charttime) <= DATETIME(CURRENT_TIME(), '-2 year')
### Instruction: how many times has patient 025-51980 produced an output of urine? ### 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 = '025-51980')) AND intakeoutput.cellpath LIKE '%output%' AND intakeoutput.celllabel = 'urine'
### Instruction: How many courses for each course description? Show me a bar chart, sort y-axis from low to high order. ### Response:
SELECT CRS_DESCRIPTION, COUNT(CRS_DESCRIPTION) FROM CLASS AS T1 JOIN EMPLOYEE AS T2 ON T1.PROF_NUM = T2.EMP_NUM JOIN COURSE AS T3 ON T1.CRS_CODE = T3.CRS_CODE GROUP BY CRS_DESCRIPTION ORDER BY COUNT(CRS_DESCRIPTION)
### Instruction: how many hours have elapsed since the last time patient 016-9636 stayed in the ward 613 in this hospital visit? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', patient.unitadmittime)) FROM patient WHERE patient.uniquepid = '016-9636' AND patient.wardid = 613 AND patient.hospitaldischargetime IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1
### Instruction: Percentage of closed questions by each hour of the day. ### Response:
SELECT TIME_TO_STR(q.CreationDate, '%I') AS "Hour", CAST((100.0 * COUNT(q.ClosedDate) / COUNT(*)) AS FLOAT(10, 0)) AS "Closed percent", COUNT(*) AS "question_count" FROM Posts AS q WHERE q.PostTypeId = 1 GROUP BY TIME_TO_STR(q.CreationDate, '%I') ORDER BY 'Hour'
### Instruction: have patient 007-2065 had any lab testing done until 2 years ago? ### 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 = '007-2065')) AND DATETIME(lab.labresulttime) <= DATETIME(CURRENT_TIME(), '-2 year')
### Instruction: get me the number of patients with blood lab test who have the diagnoses of dementia in conditions classifed elsewhere without behavioral disturbance. ### 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 = "Dementia in conditions classified elsewhere without behavioral disturbance" AND lab.fluid = "Blood"
### Instruction: what is the unabbreviated version of the imp crtd sinus stm,totl? ### Response:
SELECT d_icd_diagnoses.long_title FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'imp crtd sinus stm,totl' UNION SELECT d_icd_procedures.long_title FROM d_icd_procedures WHERE d_icd_procedures.short_title = 'imp crtd sinus stm,totl'
### Instruction: count the number of patients whose ethnicity is american indian/alaska native and procedure long title is initial insertion of single-chamber device, rate responsive? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.ethnicity = "AMERICAN INDIAN/ALASKA NATIVE" AND procedures.long_title = "Initial insertion of single-chamber device, rate responsive"
### Instruction: when was the last time during their first hospital encounter that patient 17608 was prescribed a drug via subcut? ### Response:
SELECT prescriptions.startdate FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17608 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime LIMIT 1) AND prescriptions.route = 'subcut' ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: number of patients who had a viral culture:r/o herpes simplex virus microbiology test in 2104. ### Response:
SELECT COUNT(DISTINCT admissions.subject_id) FROM admissions WHERE admissions.hadm_id IN (SELECT microbiologyevents.hadm_id FROM microbiologyevents WHERE microbiologyevents.spec_type_desc = 'viral culture:r/o herpes simplex virus' AND STRFTIME('%y', microbiologyevents.charttime) = '2104')
### Instruction: Most Cassandra Questions answered for 2015. ### Response:
SELECT Users.DisplayName, COUNT(*) AS questions FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.Id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Users ON Users.Id = Posts.OwnerUserId WHERE Tags.Id = 34113 AND Posts.CreationDate > '2015-01-01 00:00:00' GROUP BY Users.DisplayName ORDER BY questions DESC
### Instruction: what is the number of patients whose diagnoses short title is hx surgery to organs nec and drug route is iv drip? ### 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 = "Hx surgery to organs NEC" AND prescriptions.route = "IV DRIP"
### Instruction: how many hours have passed since patient 032-24135 first visited the ward 1068 during the current hospital encounter? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', patient.unitadmittime)) FROM patient WHERE patient.uniquepid = '032-24135' AND patient.wardid = 1068 AND patient.hospitaldischargetime IS NULL ORDER BY patient.unitadmittime LIMIT 1
### Instruction: How many upvotes do I have for each tag? Non-wiki. how long before I get tag badges? ### Response:
SELECT TagName, COUNT(*) AS UpVotes FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.Id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id AND VoteTypeId = 2 WHERE Posts.OwnerUserId = @UserId AND CommunityOwnedDate IS NULL GROUP BY TagName ORDER BY UpVotes DESC
### Instruction: what is the five most frequently taken in lab tests until 2102? ### 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 STRFTIME('%y', labevents.charttime) <= '2102' GROUP BY labevents.itemid) AS t1 WHERE t1.c1 <= 5)
### Instruction: count the number of patients who are diagnosed with gi obstruction / ileus - small bowel obstruction since 2 years ago. ### Response:
SELECT COUNT(DISTINCT patient.uniquepid) FROM patient WHERE patient.patientunitstayid IN (SELECT diagnosis.patientunitstayid FROM diagnosis WHERE diagnosis.diagnosisname = 'gi obstruction / ileus - small bowel obstruction' AND DATETIME(diagnosis.diagnosistime) >= DATETIME(CURRENT_TIME(), '-2 year'))
### Instruction: give me the number of patients whose diagnoses long title is malignant neoplasm of other sites of tongue and lab test abnormal status is abnormal? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE diagnoses.long_title = "Malignant neoplasm of other sites of tongue" AND lab.flag = "abnormal"
### Instruction: provide the number of patients whose admission type is emergency and diagnoses long title is other drugs and medicinal substances causing adverse effects in therapeutic use? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.admission_type = "EMERGENCY" AND diagnoses.long_title = "Other drugs and medicinal substances causing adverse effects in therapeutic use"
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, return a bar chart about the distribution of first_name and commission_pct , and order by the FIRST_NAME in asc please. ### Response:
SELECT FIRST_NAME, COMMISSION_PCT FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY FIRST_NAME
### Instruction: What courses does Ulysses Balis teach ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course, course_offering, instructor, offering_instructor WHERE course.course_id = course_offering.course_id AND instructor.name LIKE '%Ulysses Balis%' AND offering_instructor.instructor_id = instructor.instructor_id AND offering_instructor.offering_id = course_offering.offering_id
### Instruction: how many hours have passed since first time that patient 027-32001 stayed in ward 962 during the current hospital encounter? ### Response:
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', patient.unitadmittime)) FROM patient WHERE patient.uniquepid = '027-32001' AND patient.wardid = 962 AND patient.hospitaldischargetime IS NULL ORDER BY patient.unitadmittime LIMIT 1
### Instruction: what was the name of the lab test patient 035-4312 first had in their current hospital visit? ### Response:
SELECT lab.labname FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '035-4312' AND patient.hospitaldischargetime IS NULL)) ORDER BY lab.labresulttime LIMIT 1
### Instruction: Since 2004 who has published works about fibromyalgia and diet ? ### Response:
SELECT DISTINCT writes.authorid FROM keyphrase, paper, paperkeyphrase, writes WHERE keyphrase.keyphrasename IN ('fibromyalgia', 'diet') AND paperkeyphrase.keyphraseid = keyphrase.keyphraseid AND paper.paperid = paperkeyphrase.paperid AND paper.year > 2004 AND writes.paperid = paper.paperid GROUP BY writes.authorid
### Instruction: give me the number of patients whose primary disease is hypertension;rule out coronary artery disease\cardiac cath and lab test category is chemistry? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE demographic.diagnosis = "HYPERTENSION;RULE OUT CORONARY ARTERY DISEASE\CARDIAC CATH" AND lab."CATEGORY" = "Chemistry"
### Instruction: did patient 25590 have laboratory test in 02/this year? ### Response:
SELECT COUNT(*) > 0 FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25590) AND DATETIME(labevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', labevents.charttime) = '02'
### Instruction: how many times is the nafcillin desensitization since 68 months ago prescribed to patient 17694? ### Response:
SELECT COUNT(*) FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17694) AND prescriptions.drug = 'nafcillin desensitization' AND DATETIME(prescriptions.startdate) >= DATETIME(CURRENT_TIME(), '-68 month')
### Instruction: What is the lowest Euler characteristic: V-E+F of a hexahedron or cube, which has less than 20 faces F, less than 30 edges E, and less than 8 vertices V? ### Response:
SELECT MIN("Euler characteristic: V \u2212 E + F") FROM table_4937 WHERE "Faces F" < '20' AND "Edges E" < '30' AND "Name" = 'hexahedron or cube' AND "Vertices V" < '8'
### Instruction: what's the five most frequently taken lab test until 2100? ### 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 STRFTIME('%y', labevents.charttime) <= '2100' GROUP BY labevents.itemid) AS t1 WHERE t1.c1 <= 5)
### Instruction: What was the WJC rank in San Francisco metro area with the ASARB Jews less than 261,100 and WJC Jews of more than 210,000? ### Response:
SELECT AVG("Rank ( WJC )") FROM table_51946 WHERE "Number of Jews (ASARB)" < '261,100' AND "Metro area" = 'san francisco' AND "Number of Jews (WJC)" > '210,000'
### Instruction: Do any RCLANG classes occur other than on Friday ? ### 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 WHERE course_offering.friday = 'N' AND course.department = 'RCLANG' AND semester.semester = 'WN' AND semester.year = 2016
### Instruction: tell me the average yearly number of patients diagnosed with external ear injury - right since 2105? ### Response:
SELECT AVG(t1.c1) FROM (SELECT COUNT(DISTINCT diagnosis.patientunitstayid) AS c1 FROM diagnosis WHERE diagnosis.diagnosisname = 'external ear injury - right' AND STRFTIME('%y', diagnosis.diagnosistime) >= '2105' GROUP BY STRFTIME('%y', diagnosis.diagnosistime)) AS t1
### Instruction: Who are the experts in Python ?. ### Response:
SELECT Id, Reputation, DisplayName, WebsiteUrl, total FROM Users LEFT JOIN (SELECT OwnerUserId, COUNT(*) AS total FROM (SELECT OwnerUserId, PostTypeId FROM Posts WHERE PostTypeId = 2 AND ParentId IN (SELECT PostId FROM PostTags WHERE TagId = (SELECT Id FROM Tags WHERE TagName = '##TagName##'))) AS T GROUP BY OwnerUserId) AS F ON Id = OwnerUserId WHERE total >= 2 ORDER BY total DESC, Reputation DESC
### Instruction: What the [A] that has more than 8.29 as the H2PO 4 and 1.30 10 8 as the PO4 3? ### Response:
SELECT "[A] (mol/L)" FROM table_13628 WHERE "[H 2 PO 4 \u2212 ]/[A] (%)" > '8.29' AND "[PO 4 3\u2212 ]/[A] (%)" = '1.30×10 −8'
### Instruction: what are the four most frequently prescribed drugs in patients with age 50s? ### Response:
SELECT t1.drugname FROM (SELECT medication.drugname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM medication WHERE medication.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 50 AND 59) GROUP BY medication.drugname) AS t1 WHERE t1.c1 <= 4
### Instruction: List the document ids of documents with the status done and type Paper, which not shipped by the shipping agent named USPS. ### Response:
SELECT document_id FROM Documents WHERE document_status_code = "done" AND document_type_code = "Paper" EXCEPT SELECT document_id FROM Documents JOIN Ref_Shipping_Agents ON Documents.shipping_agent_code = Ref_Shipping_Agents.shipping_agent_code WHERE Ref_Shipping_Agents.shipping_agent_name = "USPS"
### Instruction: when did patient 9241 have a microbiology test for the last time since 04/2105? ### Response:
SELECT microbiologyevents.charttime FROM microbiologyevents WHERE microbiologyevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 9241) AND STRFTIME('%y-%m', microbiologyevents.charttime) >= '2105-04' ORDER BY microbiologyevents.charttime DESC LIMIT 1
### Instruction: Show details of all investors if they make any transaction with share count greater than 100, and count them by a bar chart, I want to show by the y-axis from high to low. ### Response:
SELECT Investor_details, COUNT(Investor_details) FROM Investors AS T1 JOIN Transactions AS T2 ON T1.investor_id = T2.investor_id WHERE T2.share_count > 100 GROUP BY Investor_details ORDER BY COUNT(Investor_details) DESC
### Instruction: what is the number of patients with parox ventric tachyard diagnosis and with procedure insertion of endotracheal tube? ### 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 = "Parox ventric tachycard" AND procedures.long_title = "Insertion of endotracheal tube"
### Instruction: show me the number of patients who have diagnoses icd9 code 28860 along with additive type drug prescription. ### 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.icd9_code = "28860" AND prescriptions.drug_type = "ADDITIVE"
### Instruction: what the first height of patient 030-67523 in their last hospital encounter. ### Response:
SELECT patient.admissionheight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '030-67523' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1) AND NOT patient.admissionheight IS NULL ORDER BY patient.unitadmittime LIMIT 1
### Instruction: tell me the name of the specimen test that patient 031-3507 had last received? ### Response:
SELECT microlab.culturesite FROM microlab WHERE microlab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '031-3507')) ORDER BY microlab.culturetakentime DESC LIMIT 1
### Instruction: Which Intermediate Quechua , courses will satisfy the MDE requirement ? ### Response:
SELECT DISTINCT course.department, course.name, course.number FROM course INNER JOIN area ON course.course_id = area.course_id INNER JOIN program_course ON program_course.course_id = course.course_id WHERE (area.area LIKE '%Intermediate Quechua ,%' OR course.description LIKE '%Intermediate Quechua ,%' OR course.name LIKE '%Intermediate Quechua ,%') AND program_course.category LIKE '%MDE%'
### Instruction: what is the number of patients whose ethnicity is hispanic/latino - puerto rican and diagnoses icd9 code is 51889? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.ethnicity = "HISPANIC/LATINO - PUERTO RICAN" AND diagnoses.icd9_code = "51889"
### Instruction: what is the four most frequent specimen test that was taken since 1 year ago? ### Response:
SELECT t1.spec_type_desc FROM (SELECT microbiologyevents.spec_type_desc, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM microbiologyevents WHERE DATETIME(microbiologyevents.charttime) >= DATETIME(CURRENT_TIME(), '-1 year') GROUP BY microbiologyevents.spec_type_desc) AS t1 WHERE t1.c1 <= 4
### Instruction: Which Opponent in the final has an Outcome of winner, and a Date larger than 1992, and a Surface of clay, and a Score in the final of 3 6, 6 2, 6 1? ### Response:
SELECT opponent_in_the_final FROM table_name_65 WHERE outcome = "winner" AND date > 1992 AND surface = "clay" AND score_in_the_final = "3–6, 6–2, 6–1"