instruction
stringlengths
37
754
output
stringlengths
9
3.43k
### Instruction: what is the number of patients who have been daignosed with status-post ptca and dialys as the drug route? ### 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 = "Status-post ptca" AND prescriptions.route = "DIALYS"
### Instruction: provide me the number of patients on ng route of drug administration who have diagnoses icd9 code 99662. ### 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 = "99662" AND prescriptions.route = "NG"
### Instruction: For those employees who was hired before 2002-06-21, find job_id and the average of department_id , and group by attribute job_id, and visualize them by a bar chart, I want to order by the X-axis from high to low. ### Response:
SELECT JOB_ID, AVG(DEPARTMENT_ID) FROM employees WHERE HIRE_DATE < '2002-06-21' GROUP BY JOB_ID ORDER BY JOB_ID DESC
### Instruction: CV Most Interesting Users - Only Counting 'immediate' votes. ### Response:
SELECT COUNT(*) AS score, p.Id, p.OwnerUserId FROM Votes AS v, Posts AS p, Posts AS p2 WHERE v.VoteTypeId = 2 AND v.PostId = p.Id AND p.ParentId = p2.Id AND v.CreationDate - p2.CreationDate < 14 GROUP BY p.Id, p.OwnerUserId HAVING COUNT(*) > 10
### Instruction: has patient 027-188709 been given any diagnosis in the current hospital encounter? ### 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 = '027-188709' AND patient.hospitaldischargetime IS NULL))
### Instruction: give me the number of patients whose primary disease is sigmoid diverticulitis, colovestical fistula/sda and year of death is less than or equal to 2133? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic WHERE demographic.diagnosis = "SIGMOID DIVERTICULITIS, COLOVESTICAL FISTULA/SDA" AND demographic.dod_year <= "2133.0"
### Instruction: What is the weekday of birthdates of the professors in charge of ACCT-211? Visualize with a bar chart, I want to sort in asc by the y-axis. ### Response:
SELECT EMP_DOB, COUNT(EMP_DOB) FROM EMPLOYEE AS T1 JOIN CLASS AS T2 ON T1.EMP_NUM = T2.PROF_NUM WHERE CRS_CODE = "ACCT-211" ORDER BY COUNT(EMP_DOB)
### Instruction: count the number of patients whose diagnoses icd9 code is 41519 and lab test category is chemistry? ### 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.icd9_code = "41519" AND lab."CATEGORY" = "Chemistry"
### Instruction: What roles did staff members play between '2003-04-19 15:06:20' and '2016-03-15 00:33:18'? ### Response:
SELECT role_code FROM project_staff WHERE date_from > '2003-04-19 15:06:20' AND date_to < '2016-03-15 00:33:18'
### Instruction: What are the purchase details of transactions with amount bigger than 10000, and count them by a bar chart, rank by the the number of purchase details from high to low. ### Response:
SELECT purchase_details, COUNT(purchase_details) FROM Purchases AS T1 JOIN Transactions AS T2 ON T1.purchase_transaction_id = T2.transaction_id WHERE T2.amount_of_transaction > 10000 GROUP BY purchase_details ORDER BY COUNT(purchase_details) DESC
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, draw a line chart about the change of department_id over hire_date , and order x axis in asc order. ### Response:
SELECT HIRE_DATE, DEPARTMENT_ID FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY HIRE_DATE
### Instruction: What is the mean Evaluation number (Before April 2009) when the percentage of negative evaluations was 0.8% and the mean Evaluation number of April 2009 was 4.2? ### Response:
SELECT evaluation_average__before_april_2009_ FROM table_name_41 WHERE _percentage_of_negative_evaluations = "0.8%" AND evaluation_average__from_april_2009_ = "4.2"
### Instruction: was the furosemide prescribed to patient 1372 until 07/2101? ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 1372) AND prescriptions.drug = 'furosemide' AND STRFTIME('%y-%m', prescriptions.startdate) <= '2101-07'
### Instruction: count the number of patients whose diagnoses icd9 code is 76528 and lab test category is chemistry? ### 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.icd9_code = "76528" AND lab."CATEGORY" = "Chemistry"
### Instruction: count the number of patients whose diagnoses short title is hemorrhage complic proc and drug type is main? ### 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 = "Hemorrhage complic proc" AND prescriptions.drug_type = "MAIN"
### Instruction: ACL papers in 2012 on parsing ### Response:
SELECT DISTINCT paper.paperid FROM keyphrase, paper, paperkeyphrase, venue WHERE keyphrase.keyphrasename = 'parsing' AND paperkeyphrase.keyphraseid = keyphrase.keyphraseid AND paper.paperid = paperkeyphrase.paperid AND paper.year = 2012 AND venue.venueid = paper.venueid AND venue.venuename = 'ACL'
### Instruction: count the number of patients on main drug type prescription who have diagnoses icd9 code 2752. ### 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 = "2752" AND prescriptions.drug_type = "MAIN"
### Instruction: count the number of patients whose diagnoses short title is open wound of face nos and drug route is po/ng? ### 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 = "Open wound of face NOS" AND prescriptions.route = "PO/NG"
### Instruction: find out the number of patients admitted before 2123 who were diagnosed with acute on chronic combined systolic and diastolic heart failure. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.admityear < "2123" AND diagnoses.long_title = "Acute on chronic combined systolic and diastolic heart failure"
### Instruction: what is the number of patients whose primary disease is sigmoid diverticulitis, colovestical fistula/sda and year of death is less than or equal to 2112? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic WHERE demographic.diagnosis = "SIGMOID DIVERTICULITIS, COLOVESTICAL FISTULA/SDA" AND demographic.dod_year <= "2112.0"
### Instruction: provide the number of patients whose diagnoses short title is skin disorders nec 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.short_title = "Skin disorders NEC" AND prescriptions.drug_type = "ADDITIVE"
### Instruction: has patient 007-16517 been prescribed any prescription drugs during this hospital visit? ### 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 = '007-16517' AND patient.hospitaldischargetime IS NULL))
### Instruction: list of patient ids of patients who have been diagnosed with gastroparesis. ### Response:
SELECT admissions.subject_id FROM admissions WHERE admissions.hadm_id IN (SELECT diagnoses_icd.hadm_id FROM diagnoses_icd WHERE diagnoses_icd.icd9_code = (SELECT d_icd_diagnoses.icd9_code FROM d_icd_diagnoses WHERE d_icd_diagnoses.short_title = 'gastroparesis'))
### Instruction: Which Total population (2005 estimate) has a Province of west kalimantan (kalimantan barat), and an Area (km 2) smaller than 147,307.00? ### Response:
SELECT AVG("Total population (2005 estimate)") FROM table_9332 WHERE "Province" = 'west kalimantan (kalimantan barat)' AND "Area (km 2 )" < '147,307.00'
### Instruction: what is the number of patients whose diagnoses icd9 code is 28860 and lab test fluid is other body fluid? ### 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.icd9_code = "28860" AND lab.fluid = "Other Body Fluid"
### Instruction: What is the lowest population total in La Romana when the area is less than 1,788.4, the density is greater than 234.77, and a rank greater than 30 ### Response:
SELECT MIN("Population") FROM table_42664 WHERE "Area" < '1,788.4' AND "Density" > '234.77' AND "Province" = 'la romana' AND "Rank" > '30'
### Instruction: For those employees who was hired before 2002-06-21, draw a bar chart about the distribution of job_id and the sum of employee_id , and group by attribute job_id, order in asc by the y-axis please. ### Response:
SELECT JOB_ID, SUM(EMPLOYEE_ID) FROM employees WHERE HIRE_DATE < '2002-06-21' GROUP BY JOB_ID ORDER BY SUM(EMPLOYEE_ID)
### Instruction: out of these drivers : nigel mansell , al unser , jr. , michael schumacher , and jeff gordon , all but one has more than one espy award . who only has one espy award ? ### Response:
SELECT "driver" FROM table_203_364 WHERE "driver" IN ('nigel mansell', 'al unser, jr', 'michael schumacher', 'jeff gordon') GROUP BY "driver" HAVING COUNT(*) = 1
### Instruction: RANK, parition by id order by value_type. ### Response:
WITH test AS (SELECT 1 AS id, 'B' AS value_type UNION ALL SELECT 1, 'B' UNION ALL SELECT 1, 'A' UNION ALL SELECT 2, 'A' UNION ALL SELECT 2, 'A'), summary AS (SELECT t.*, RANK() OVER (PARTITION BY t.id ORDER BY t.value_type DESC) AS rank FROM test AS t) SELECT * FROM summary WHERE rank = 1
### Instruction: provide the number of patients whose diagnoses short title is ami inferolateral, init and lab test category is chemistry? ### 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 = "AMI inferolateral, init" AND lab."CATEGORY" = "Chemistry"
### Instruction: provide the number of patients whose diagnoses icd9 code is e9331 and drug type is main? ### 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 = "E9331" AND prescriptions.drug_type = "MAIN"
### Instruction: For those employees who was hired before 2002-06-21, a bar chart shows the distribution of job_id and the average of department_id , and group by attribute job_id, could you rank by the y-axis from low to high? ### Response:
SELECT JOB_ID, AVG(DEPARTMENT_ID) FROM employees WHERE HIRE_DATE < '2002-06-21' GROUP BY JOB_ID ORDER BY AVG(DEPARTMENT_ID)
### Instruction: what was the name of the drug, which was prescribed to patient 25796 for the last time in the last hospital visit? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25796 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) ORDER BY prescriptions.startdate DESC LIMIT 1
### Instruction: how many patients diagnosed with arthropathy nos-unspec received po/ng therapy? ### 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 = "Arthropathy NOS-unspec" AND prescriptions.route = "PO/NG"
### Instruction: Find the number of patients who had procedure a called contrast arterigram-leg and a discharge location of disc-tran cancer/chldrn. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.discharge_location = "DISC-TRAN CANCER/CHLDRN H" AND procedures.short_title = "Contrast arteriogram-leg"
### Instruction: how many patients with admission location as clinic referral/premature were diagnosed with diverticulosis of colon with hemorrhage? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.admission_location = "CLINIC REFERRAL/PREMATURE" AND diagnoses.long_title = "Diverticulosis of colon with hemorrhage"
### Instruction: provide the number of patients whose diagnoses short title is hx-rectal & anal malign 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.short_title = "Hx-rectal & anal malign" AND lab.flag = "abnormal"
### 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 email and department_id , and order from low to high by the y-axis please. ### Response:
SELECT EMAIL, DEPARTMENT_ID FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY DEPARTMENT_ID
### Instruction: Are there Economic Sociology ULCS courses ? ### 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 '%Economic Sociology%' OR course.description LIKE '%Economic Sociology%' OR course.name LIKE '%Economic Sociology%') AND program_course.category LIKE '%ULCS%'
### Instruction: Return the names of countries that have players that play the Forward position, as well as players who play the Defender position. ### Response:
SELECT T1.country_name FROM country AS T1 JOIN match_season AS T2 ON T1.country_id = T2.country WHERE T2.position = "Forward" INTERSECT SELECT T1.country_name FROM country AS T1 JOIN match_season AS T2 ON T1.country_id = T2.country WHERE T2.position = "Defender"
### Instruction: did albumin 5% (25 g), d5 1/2ns, or vial be prescribed to patient 3118? ### Response:
SELECT COUNT(*) > 0 FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 3118) AND prescriptions.drug IN ('albumin 5% (25 g)', 'd5 1/2ns', 'vial')
### Instruction: give the number of patients whose drug code is ketr30i and lab test fluid is joint fluid. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE prescriptions.formulary_drug_cd = "KETR30I" AND lab.fluid = "Joint Fluid"
### Instruction: provide the number of patients whose drug code is infl0.5lf and lab test fluid is blood. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE prescriptions.formulary_drug_cd = "INFL0.5LF" AND lab.fluid = "Blood"
### Instruction: give me the number of patients whose admission type is elective and procedure long title is insertion of non-drug-eluting coronary artery stent(s)? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.admission_type = "ELECTIVE" AND procedures.long_title = "Insertion of non-drug-eluting coronary artery stent(s)"
### Instruction: what is the number of patients whose diagnoses short title is prsnl hst colonic polyps and lab test fluid is blood? ### 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 = "Prsnl hst colonic polyps" AND lab.fluid = "Blood"
### Instruction: Which customers have both 'On Road' and 'Shipped' as order status? List the customer ids. ### Response:
SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "On Road" INTERSECT SELECT T1.customer_id FROM customers AS T1 JOIN orders AS T2 ON T1.customer_id = T2.customer_id WHERE T2.order_status = "Shipped"
### Instruction: Top 100 users with most gold badges for a Country. ### Response:
SELECT u.Location, u.Id, u.DisplayName, bd.NumTagBadges FROM (SELECT UserId, COUNT(*) AS NumTagBadges FROM Badges WHERE Name IN (SELECT TagName FROM Tags WHERE COALESCE(TagName, '') != '') GROUP BY UserId LIMIT 100) AS bd JOIN Users AS u ON u.Id = bd.UserId WHERE u.Location LIKE ('%##CountryName##%')
### Instruction: Top Android Russia Answers writers. ### Response:
SELECT u.Id, u.DisplayName, u.Reputation, COUNT(*) AS AndroidAnswers FROM Users AS u, Posts AS p, Posts AS pp WHERE u.Id IN (SELECT Id FROM Users WHERE Location LIKE ('%Russia')) AND p.OwnerUserId = u.Id AND pp.Id = p.ParentId AND pp.Tags LIKE ('%android%') GROUP BY u.Id, u.DisplayName, u.Reputation ORDER BY AndroidAnswers DESC
### Instruction: For those employees who do not work in departments with managers that have ids between 100 and 200, show me about the distribution of first_name and salary in a bar chart, I want to rank by the total number in ascending. ### Response:
SELECT FIRST_NAME, SALARY FROM employees WHERE NOT DEPARTMENT_ID IN (SELECT DEPARTMENT_ID FROM departments WHERE MANAGER_ID BETWEEN 100 AND 200) ORDER BY SALARY
### Instruction: For those employees who was hired before 2002-06-21, show me about the distribution of hire_date and the average of department_id bin hire_date by weekday in a bar chart, and rank by the the average of department id from low to high. ### Response:
SELECT HIRE_DATE, AVG(DEPARTMENT_ID) FROM employees WHERE HIRE_DATE < '2002-06-21' ORDER BY AVG(DEPARTMENT_ID)
### Instruction: how many patients whose diagnoses long title is interstitial emphysema and related conditions 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 = "Interstitial emphysema and related conditions" AND lab.flag = "abnormal"
### Instruction: count the number of patients whose diagnoses long title is abscess of intestine and drug route is dialys? ### 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 = "Abscess of intestine" AND prescriptions.route = "DIALYS"
### Instruction: What is the number of partners for the city ranked under 294, total over 264, largest city of Chicago, and other over 46? ### Response:
SELECT "Partners\u2003" FROM table_64054 WHERE "Rank\u2003" < '294' AND "Total" > '264' AND "Largest U.S. City\u2003" = 'chicago' AND "Other" > '46'
### Instruction: give me the number of patients whose diagnosis icd9 code is 25060 and blood was taken as the lab test fluid. ### 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.icd9_code = "25060" AND lab.fluid = "Blood"
### Instruction: What is the tax source system code related to the benefits and overpayments? List the code and the benifit id, order by benifit id. ### Response:
SELECT T1.source_system_code, T2.council_tax_id FROM CMI_Cross_References AS T1 JOIN Benefits_Overpayments AS T2 ON T1.cmi_cross_ref_id = T2.cmi_cross_ref_id ORDER BY T2.council_tax_id
### Instruction: how long was the last time patient 67687 was in intensive care? ### Response:
SELECT STRFTIME('%j', icustays.outtime) - STRFTIME('%j', icustays.intime) FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 67687) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime DESC LIMIT 1
### Instruction: For those employees who was hired before 2002-06-21, show me about the distribution of job_id and the sum of employee_id , and group by attribute job_id in a bar chart, and I want to order JOB_ID in asc order. ### Response:
SELECT JOB_ID, SUM(EMPLOYEE_ID) FROM employees WHERE HIRE_DATE < '2002-06-21' GROUP BY JOB_ID ORDER BY JOB_ID
### Instruction: provide the number of patients whose diagnoses icd9 code is 5679 and drug type is main? ### 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 = "5679" AND prescriptions.drug_type = "MAIN"
### Instruction: Percentage of users with rep=1 and with just a single question post. ### Response:
SELECT (1.0 * (SELECT COUNT(*) FROM (SELECT u.Id FROM (SELECT Id FROM Users WHERE Reputation = 1) AS u JOIN Posts AS p ON u.Id = p.OwnerUserId GROUP BY u.Id HAVING COUNT(*) = 1 AND MAX(p.PostTypeId) = 1) AS Chosen)) / (1.0 * (SELECT COUNT(*) FROM Users)) * 100
### Instruction: provide the number of patients whose diagnoses icd9 code is 4280 and drug type is main? ### 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 = "4280" AND prescriptions.drug_type = "MAIN"
### Instruction: Recent posts by MathOverflow moderators. ### Response:
SELECT u.Id AS "user_link", u.LastAccessDate, p.CreationDate, p.Id AS "post_link" FROM Users AS u INNER JOIN Posts AS p ON p.OwnerUserId = u.Id WHERE u.Id IN (2, 3, 66, 121, 1409, 2000, 2926) ORDER BY p.CreationDate DESC LIMIT 100
### Instruction: vba questions daily, 60 days. ### Response:
SELECT DATEPART(ww, CreationDate) AS "week", COUNT(*) AS "vba_questions" FROM Posts WHERE Tags LIKE '%vba>%' AND PostTypeId = 1 AND CreationDate >= DATEADD(d, -60, GETDATE()) AND DATEPART(ww, CreationDate) < DATEPART(ww, GETDATE()) - 1 GROUP BY DATEPART(ww, CreationDate) ORDER BY DATEPART(ww, CreationDate)
### Instruction: what was the last value on the sodium lab test of patient 42956? ### Response:
SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 42956) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'sodium') ORDER BY labevents.charttime DESC LIMIT 1
### Instruction: calculate the number of patients who have had a skin scrapings microbiology test since 1 year ago. ### 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 = 'skin scrapings' AND DATETIME(microbiologyevents.charttime) >= DATETIME(CURRENT_TIME(), '-1 year'))
### 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 the relationship between commission_pct and department_id . ### Response:
SELECT COMMISSION_PCT, 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 short title is hx of colonic malignancy 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.short_title = "Hx of colonic malignancy" AND prescriptions.route = "IV"
### Instruction: what are the top three most frequently performed lab tests among the patients 50s? ### Response:
SELECT t1.labname FROM (SELECT lab.labname, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM lab WHERE lab.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.age BETWEEN 50 AND 59) GROUP BY lab.labname) AS t1 WHERE t1.c1 <= 3
### Instruction: since 2105 tell me the four most common output events? ### Response:
SELECT t1.celllabel FROM (SELECT intakeoutput.celllabel, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM intakeoutput WHERE intakeoutput.cellpath LIKE '%output%' AND STRFTIME('%y', intakeoutput.intakeoutputtime) >= '2105' GROUP BY intakeoutput.celllabel) AS t1 WHERE t1.c1 <= 4
### Instruction: A bar chart for giveing me the number of the descriptions of the service types that cost more than 100, and display total number in ascending order. ### Response:
SELECT Service_Type_Description, COUNT(Service_Type_Description) FROM Ref_Service_Types AS T1 JOIN Services AS T2 ON T1.Service_Type_Code = T2.Service_Type_Code WHERE T2.Product_Price > 100 GROUP BY Service_Type_Description ORDER BY COUNT(Service_Type_Description)
### Instruction: Get the average size of a question for a tag grouped by quarter. ### Response:
SELECT DATEADD(quarter, DATEDIFF(quarter, 0, CreationDate), 0), AVG(LEN(p.Body)) FROM Posts AS p INNER JOIN PostTags AS pt ON pt.TagId = @TagId WHERE pt.PostId = p.Id AND p.PostTypeId = 1 GROUP BY DATEADD(quarter, DATEDIFF(quarter, 0, CreationDate), 0)
### Instruction: How many patients were diagnosed with atherosclerosis of native arteries of the extremities (unspecified) and were admitted before the year 2178? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.admityear < "2178" AND diagnoses.short_title = "Athscl extrm ntv art NOS"
### Instruction: give me the number of patients whose diagnoses short title is tietze's disease and drug type is main? ### 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 = "Tietze's disease" AND prescriptions.drug_type = "MAIN"
### Instruction: What is the highest Played, when Average is less than 0.903, when 1992-93 is 25, and when 1994-1995 is greater than 38? ### Response:
SELECT MAX("Played") FROM table_9669 WHERE "Average" < '0.903' AND "1992-93" = '25' AND "1994-1995" > '38'
### Instruction: let me know the number of patients with drug code ris1l for whom pleural fluid lab test order was placed. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE prescriptions.formulary_drug_cd = "RIS1L" AND lab.fluid = "Pleural"
### Instruction: how many patients whose diagnoses short title is acute pancreatitis 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.short_title = "Acute pancreatitis" AND prescriptions.drug_type = "ADDITIVE"
### Instruction: users who took a long break from posting on an SE site?. http://meta.stackexchange.com/questions/245972/how-to-find-the-users-who-took-a-long-break-from-posting-on-an-se-site#245972 ### Response:
SELECT Users.Id, Users.EmailHash, Users.WebsiteUrl FROM Users WHERE Users.CreationDate >= '##year:int##' AND Users.Location LIKE '%##location##%'
### Instruction: give me the number of patients whose diagnoses short title is history of tobacco use 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 = "History of tobacco use" AND lab."CATEGORY" = "Blood Gas"
### Instruction: what is the number of patients whose days of hospital stay is greater than 30 and diagnoses long title is contact dermatitis and other eczema, unspecified cause? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN diagnoses ON demographic.hadm_id = diagnoses.hadm_id WHERE demographic.days_stay > "30" AND diagnoses.long_title = "Contact dermatitis and other eczema, unspecified cause"
### Instruction: A bar chart for what are the number of the purchase details of transactions with amount bigger than 10000?, and could you rank in asc by the the number of purchase details? ### Response:
SELECT purchase_details, COUNT(purchase_details) FROM Purchases AS T1 JOIN Transactions AS T2 ON T1.purchase_transaction_id = T2.transaction_id WHERE T2.amount_of_transaction > 10000 GROUP BY purchase_details ORDER BY COUNT(purchase_details)
### Instruction: how many patients whose diagnoses short title is schizophrenia nos-unspec 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.short_title = "Schizophrenia NOS-unspec" AND lab.flag = "abnormal"
### Instruction: provide me the number of patients with routine circumcision diagnoses who have additive type of 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.short_title = "Routine circumcision" AND prescriptions.drug_type = "ADDITIVE"
### Instruction: A bar chart for finding the number of the names of catalog entries with level number 8, and I want to show x-axis in desc order. ### Response:
SELECT catalog_entry_name, COUNT(catalog_entry_name) FROM Catalog_Contents AS t1 JOIN Catalog_Contents_Additional_Attributes AS t2 ON t1.catalog_entry_id = t2.catalog_entry_id WHERE t2.catalog_level_number = "8" GROUP BY catalog_entry_name ORDER BY catalog_entry_name DESC
### Instruction: what is the number of patients whose diagnoses icd9 code is 44020 and lab test fluid is joint fluid? ### 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.icd9_code = "44020" AND lab.fluid = "Joint Fluid"
### Instruction: give the number of patients whose discharge location is long term care hospital and procedure long title is incision of vessel, lower limb arteries. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN procedures ON demographic.hadm_id = procedures.hadm_id WHERE demographic.discharge_location = "LONG TERM CARE HOSPITAL" AND procedures.long_title = "Incision of vessel, lower limb arteries"
### Instruction: What are the name and primarily affiliated department name of each physician?, and list y axis from low to high order. ### Response:
SELECT T3.Name, COUNT(T3.Name) FROM Physician AS T1 JOIN Affiliated_With AS T2 ON T1.EmployeeID = T2.Physician JOIN Department AS T3 ON T2.Department = T3.DepartmentID WHERE T2.PrimaryAffiliation = 1 GROUP BY T3.Name ORDER BY COUNT(T3.Name)
### Instruction: what was the name of a drug patient 89202 was first prescribed until 28 months ago? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 89202) AND DATETIME(prescriptions.startdate) <= DATETIME(CURRENT_TIME(), '-28 month') ORDER BY prescriptions.startdate LIMIT 1
### Instruction: For all employees who have the letters D or S in their first name, show me about the distribution of job_id and the average of employee_id , and group by attribute job_id in a bar chart, list by the y axis in desc. ### Response:
SELECT JOB_ID, AVG(EMPLOYEE_ID) FROM employees WHERE FIRST_NAME LIKE '%D%' OR FIRST_NAME LIKE '%S%' GROUP BY JOB_ID ORDER BY AVG(EMPLOYEE_ID) DESC
### Instruction: count the number of patients who had the intake of amicar since 4 years ago. ### Response:
SELECT COUNT(DISTINCT patient.uniquepid) FROM patient WHERE patient.patientunitstayid IN (SELECT intakeoutput.patientunitstayid FROM intakeoutput WHERE intakeoutput.celllabel = 'amicar' AND intakeoutput.cellpath LIKE '%input%' AND DATETIME(intakeoutput.intakeoutputtime) >= DATETIME(CURRENT_TIME(), '-4 year'))
### Instruction: how many patients are diagnosed with syst/diast hrt fail nos and tested under chemistry lab category? ### 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 = "Syst/diast hrt fail NOS" AND lab."CATEGORY" = "Chemistry"
### Instruction: what is the name of the medication that patient 23760 was last prescribed when they came to the hospital last time? ### Response:
SELECT prescriptions.drug FROM prescriptions WHERE prescriptions.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 23760 AND NOT admissions.dischtime IS NULL ORDER BY admissions.admittime DESC LIMIT 1) 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, show me about the correlation between salary and manager_id in a scatter chart. ### Response:
SELECT SALARY, MANAGER_ID FROM employees WHERE SALARY BETWEEN 8000 AND 12000 AND COMMISSION_PCT <> "null" OR DEPARTMENT_ID <> 40
### Instruction: count the number of patients with drug code keto15i who were admitted in hospital via clinic referral/premature. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE demographic.admission_location = "CLINIC REFERRAL/PREMATURE" AND prescriptions.formulary_drug_cd = "KETO15I"
### Instruction: show the top three most frequent output events until 2100? ### Response:
SELECT t1.celllabel FROM (SELECT intakeoutput.celllabel, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM intakeoutput WHERE intakeoutput.cellpath LIKE '%output%' AND STRFTIME('%y', intakeoutput.intakeoutputtime) <= '2100' GROUP BY intakeoutput.celllabel) AS t1 WHERE t1.c1 <= 3
### Instruction: when was patient 20693's first operation since 3 years ago? ### Response:
SELECT procedures_icd.charttime FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 20693) AND DATETIME(procedures_icd.charttime) >= DATETIME(CURRENT_TIME(), '-3 year') ORDER BY procedures_icd.charttime LIMIT 1
### Instruction: how many patients are admitted urgently and diagnosed with antifungal antibiotics 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 = "URGENT" AND diagnoses.long_title = "Antifungal antibiotics causing adverse effects in therapeutic use"
### Instruction: what is the number of patients whose admission location is phys referral/normal deli and drug name is bupropion (sustained release)? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE demographic.admission_location = "PHYS REFERRAL/NORMAL DELI" AND prescriptions.drug = "BuPROPion (Sustained Release)"
### Instruction: how many patients whose drug code is dapt500i and lab test fluid is ascites? ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id INNER JOIN lab ON demographic.hadm_id = lab.hadm_id WHERE prescriptions.formulary_drug_cd = "DAPT500I" AND lab.fluid = "Ascites"
### Instruction: tell me the number of patients who had hydr20/100ns drug code and died on or before 2138. ### Response:
SELECT COUNT(DISTINCT demographic.subject_id) FROM demographic INNER JOIN prescriptions ON demographic.hadm_id = prescriptions.hadm_id WHERE demographic.dod_year <= "2138.0" AND prescriptions.formulary_drug_cd = "HYDR20/100NS"
### Instruction: Show the ids and details of the investors who have at least two transactions with type code 'SALE' Plot them as bar chart, sort in desc by the y-axis. ### Response:
SELECT T1.Investor_details, T1.investor_id FROM Investors AS T1 JOIN Transactions AS T2 ON T1.investor_id = T2.investor_id WHERE T2.transaction_type_code = "SALE" ORDER BY T1.investor_id DESC
### Instruction: A bar chart for finding the number of the parties associated with the delegates from district 1 or 2 Who served as comptrollers of the parties?, I want to list by the total number from high to low. ### Response:
SELECT Comptroller, COUNT(Comptroller) FROM election AS T1 JOIN party AS T2 ON T1.Party = T2.Party_ID WHERE T1.District = 1 OR T1.District = 2 GROUP BY Comptroller ORDER BY COUNT(Comptroller) DESC