instruction
stringlengths 37
754
| output
stringlengths 9
3.43k
|
---|---|
### Instruction:
what changes have been made to the ph levels of patient 9566 second measured on the current hospital visit compared to the value first measured on the current hospital visit?
### Response:
|
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 9566 AND admissions.dischtime IS NULL) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'ph') ORDER BY labevents.charttime LIMIT 1 OFFSET 1) - (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 9566 AND admissions.dischtime IS NULL) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'ph') ORDER BY labevents.charttime LIMIT 1)
|
### Instruction:
% Answers by author account age.
### Response:
|
WITH AnswersByMonth AS (SELECT DATEADD(month, DATEDIFF(month, 0, CreationDate), 0) AS mo, COUNT(*) AS Answers FROM Posts AS a WHERE PostTypeId = 2 GROUP BY DATEADD(month, DATEDIFF(month, 0, CreationDate), 0)) SELECT mo, CAST(DATEDIFF(month, u.CreationDate, CreationDate) / 12 AS VARCHAR(8)) AS AccountAgeYears, COUNT(*) * 100.0 / Answers AS PctAnswers FROM Posts AS a JOIN AnswersByMonth AS abm ON abm.mo = DATEADD(month, DATEDIFF(month, 0, CreationDate), 0) JOIN Users AS u ON u.Id = a.OwnerUserId AND u.CreationDate < a.CreationDate WHERE PostTypeId = 2 GROUP BY mo, DATEDIFF(month, u.CreationDate, CreationDate) / 12, Answers ORDER BY mo
|
### Instruction:
all posts for specific tag to specific topic (in title-/tag-/body-content).
### Response:
|
SELECT Id, REPLACE(REPLACE(REPLACE(Title, CHAR(10) + CHAR(13), '<br />'), CHAR(10), '<br />'), CHAR(13), '<br />') AS "title", Tags, ViewCount, FavoriteCount, CreationDate, Score, REPLACE(REPLACE(REPLACE(Body, CHAR(10) + CHAR(13), '<br />'), CHAR(10), '<br />'), CHAR(13), '<br />') AS "body" FROM Posts WHERE PostTypeId = 1 AND Tags LIKE '%<' + '##tagname:string##' + '>%' AND (Title LIKE '%' + '##topic:string##' + '%' OR Tags LIKE '%<' + '##topic:string##' + '>%' OR Body LIKE '%' + '##topic:string##' + '%') AND CreationDate >= '##sinceYear:string##' ORDER BY ViewCount DESC
|
### Instruction:
show me round trips between MONTREAL and ORLANDO
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ORLANDO' AND NOT fare.round_trip_cost IS NULL AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'MONTREAL' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
dplyr plyr data.table r tidyr trends.
### Response:
|
SELECT DATEADD(mm, (YEAR(Posts.CreationDate) - 1900) * 12 + MONTH(Posts.CreationDate) - 1, 0) AS Month, Tags.TagName, COUNT(*) AS Questions FROM Tags LEFT JOIN PostTags ON PostTags.TagId = Tags.Id LEFT JOIN Posts ON Posts.Id = PostTags.PostId LEFT JOIN PostTypes ON PostTypes.Id = Posts.PostTypeId WHERE Tags.TagName IN ('dplyr', 'plyr', 'data.table', 'tidyr', 'data.frame') AND PostTypes.Name = 'Question' AND Posts.CreationDate < DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) GROUP BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName ORDER BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName
|
### Instruction:
how many patients were prescribed glucose 15 gram/60 ml bq liq within the same month following the procedure of treatment of hypercalcemia - bisphosphonates?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'treatment of hypercalcemia - bisphosphonates') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'glucose 15 gram/60 ml bq liq') AS t2 WHERE t1.treatmenttime < t2.drugstarttime AND DATETIME(t1.treatmenttime, 'start of month') = DATETIME(t2.drugstarttime, 'start of month')
|
### Instruction:
what does it cost to fly from BOSTON to OAKLAND on UA
### Response:
|
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare WHERE (CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'OAKLAND' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND flight_fare.fare_id = fare.fare_id AND flight.airline_code = 'UA' AND flight.flight_id = flight_fare.flight_id
|
### Instruction:
i want to fly from BALTIMORE to DALLAS round trip
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DALLAS' AND NOT fare.round_trip_cost IS NULL AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BALTIMORE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
R and Other Question Tags.
### Response:
|
WITH r_tags AS (SELECT p.Id AS PostId, t.TagName, p.CreationDate, p.Score, p.ViewCount, p.OwnerUserId, p.Title, p.Tags, p.AnswerCount FROM Posts AS p JOIN PostTags AS pt ON p.Id = pt.PostId JOIN Tags AS t ON t.Id = pt.TagId AND t.TagName != 'r' WHERE NOT p.AcceptedAnswerId IS NULL AND p.CreationDate >= '2015-01-01' AND p.ParentId IS NULL AND p.Tags LIKE '%<r>%') SELECT r.TagName, YEAR(r.CreationDate) AS TagYear, COUNT(*) AS TagCount, MAX(r.Score) AS MaxScore, MAX(r.ViewCount) AS MaxViewCount, MAX(r.AnswerCount) AS MaxAnswerCount FROM r_tags AS r GROUP BY r.TagName, YEAR(r.CreationDate) ORDER BY YEAR(r.CreationDate) DESC, COUNT(*) DESC
|
### Instruction:
what kind of airline is flight UA 281 from BOSTON to DENVER
### Response:
|
SELECT DISTINCT airline.airline_code FROM airline, airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE ((CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DENVER' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND flight.flight_number = 281) AND flight.airline_code = 'UA' AND flight.airline_code = airline.airline_code
|
### Instruction:
please find me a flight between BOSTON and PHILADELPHIA that arrives in PHILADELPHIA close to 5pm
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE ((flight.arrival_time <= 1730 AND flight.arrival_time >= 1630) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHILADELPHIA' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
what do you have going from ATLANTA to PHILADELPHIA serving BREAKFAST
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight, food_service WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHILADELPHIA' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code AND food_service.meal_code = flight.meal_code AND food_service.meal_description = 'BREAKFAST') AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'ATLANTA' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
how much are patient 016-5834's weight changes second measured on the first hospital visit compared to the first value measured on the first hospital visit?
### Response:
|
SELECT (SELECT patient.admissionweight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '016-5834' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1) AND NOT patient.admissionweight IS NULL ORDER BY patient.unitadmittime LIMIT 1 OFFSET 1) - (SELECT patient.admissionweight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '016-5834' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1) AND NOT patient.admissionweight IS NULL ORDER BY patient.unitadmittime LIMIT 1)
|
### Instruction:
Configuration management trends (# of Questions per Month).
### Response:
|
SELECT DATEADD(mm, (YEAR(Posts.CreationDate) - 1900) * 12 + MONTH(Posts.CreationDate) - 1, 0) AS Month, Tags.TagName, COUNT(*) AS Questions FROM Tags LEFT JOIN PostTags ON PostTags.TagId = Tags.Id LEFT JOIN Posts ON Posts.Id = PostTags.PostId LEFT JOIN PostTypes ON PostTypes.Id = Posts.PostTypeId WHERE Tags.TagName IN ('puppet', 'chef', 'cfengine', 'ansible', 'salt-stack', 'docker') AND PostTypes.Name = 'Question' AND Posts.CreationDate < DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) GROUP BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName ORDER BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName
|
### Instruction:
Most popular StackOverflow tags in May 2018.
### Response:
|
SELECT num.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS MayRank, ROW_NUMBER() OVER (ORDER BY num.Num DESC) AS TotalRank, rate.Rate AS QuestionsInMay, num.Num AS QuestionsTotal FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate < '2018-06-01' AND Posts.CreationDate >= '2018-05-01' GROUP BY TagName) AS rate INNER JOIN (SELECT COUNT(PostId) AS Num, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId GROUP BY TagName HAVING COUNT(PostId) > 800) AS num ON rate.TagName = num.TagName ORDER BY rate.rate DESC
|
### Instruction:
tell me patient 010-12376's weight change last measured on the last hospital visit compared to the value first measured on the last hospital visit?
### Response:
|
SELECT (SELECT patient.admissionweight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '010-12376' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1) AND NOT patient.admissionweight IS NULL ORDER BY patient.unitadmittime DESC LIMIT 1) - (SELECT patient.admissionweight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '010-12376' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime DESC LIMIT 1) AND NOT patient.admissionweight IS NULL ORDER BY patient.unitadmittime LIMIT 1)
|
### Instruction:
what would be cost of a round trip from PITTSBURGH to SAN FRANCISCO
### Response:
|
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
|
### Instruction:
View count statistics by age group (grouped by month).
### Response:
|
SELECT DISTINCT (DATEDIFF(MONTH, CreationDate, GETDATE())) AS "Age in months", PERCENTILE_CONT(0.25) WITHIN GROUP (ORDER BY ViewCount) OVER (PARTITION BY DATEDIFF(MONTH, CreationDate, GETDATE())) AS "25%", PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY ViewCount) OVER (PARTITION BY DATEDIFF(MONTH, CreationDate, GETDATE())) AS "50%", PERCENTILE_CONT(0.85) WITHIN GROUP (ORDER BY ViewCount) OVER (PARTITION BY DATEDIFF(MONTH, CreationDate, GETDATE())) AS "75%", ROUND(STDEV(ViewCount) OVER (PARTITION BY DATEDIFF(MONTH, CreationDate, GETDATE())), 2) AS "StDev" FROM Posts WHERE PostTypeId = 1 ORDER BY 1 DESC
|
### Instruction:
what is the difference between patient 30044's total number of inputs and outputs until 86 days ago?
### Response:
|
SELECT (SELECT SUM(inputevents_cv.amount) FROM inputevents_cv WHERE inputevents_cv.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 30044)) AND DATETIME(inputevents_cv.charttime) <= DATETIME(CURRENT_TIME(), '-86 day')) - (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 = 30044)) AND DATETIME(outputevents.charttime) <= DATETIME(CURRENT_TIME(), '-86 day'))
|
### Instruction:
i need a flight on AA from MIAMI to CHICAGO that arrives around 5pm
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE (((flight.arrival_time <= 1730 AND flight.arrival_time >= 1630) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'CHICAGO' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'MIAMI' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'AA'
|
### Instruction:
what are my choices of flights to get from CHARLOTTE to MINNEAPOLIS arriving about 7pm in MINNEAPOLIS
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE ((flight.arrival_time <= 1930 AND flight.arrival_time >= 1830) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'MINNEAPOLIS' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'CHARLOTTE' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
Users with many answers in a single tag.
### Response:
|
SELECT MAX(t.Count) AS TagCount, 'site://questions/tagged/' + MAX(t.TagName) + '|' + MAX(t.TagName) AS TagLink, COALESCE('site://users/' + CAST(p.OwnerUserId AS TEXT) + '|' + u.DisplayName, p.OwnerDisplayName) AS UserLink, COUNT(p.Id) AS UTQnCount FROM Tags AS t JOIN PostTags AS a ON a.TagId = t.Id JOIN Posts AS q ON q.Id = a.PostId JOIN Posts AS p ON p.ParentId = q.Id LEFT JOIN Users AS u ON u.Id = p.OwnerUserId WHERE p.PostTypeId = 2 GROUP BY t.Id, p.OwnerUserId, p.OwnerDisplayName, u.DisplayName HAVING '##MinCount?40##' <= COUNT(p.Id) ORDER BY MAX(t.Count) DESC, t.Id DESC, COUNT(p.Id) DESC
|
### Instruction:
what is the total amount of output (ml)-urethral catheter deanna revis, rn and rose cullom, rn non-latex 14 fr. output that patient 006-153198 have had until 12/30/2105?
### Response:
|
SELECT SUM(intakeoutput.cellvaluenumeric) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '006-153198')) AND intakeoutput.celllabel = 'output (ml)-urethral catheter deanna revis, rn and rose cullom, rn non-latex 14 fr.' AND intakeoutput.cellpath LIKE '%output%' AND STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime) <= '2105-12-30'
|
### Instruction:
Average reputation gain per day from old posts.
### Response:
|
SELECT temp.Average, u.Id AS "user_link", u.Reputation FROM (SELECT SUM(CASE p.PostTypeId WHEN 1 THEN 5 WHEN 2 THEN 10 ELSE 0 END) / 31.0 AS "Average", p.OwnerUserId FROM Votes AS v INNER JOIN Posts AS p ON v.PostId = p.Id WHERE v.VoteTypeId = 2 AND p.CreationDate < '2018-01-01' AND v.CreationDate BETWEEN '2018-07-01' AND '2018-07-31' AND p.CommunityOwnedDate IS NULL AND NOT p.OwnerUserId IS NULL GROUP BY p.OwnerUserId ORDER BY SUM(CASE p.PostTypeId WHEN 1 THEN 5 WHEN 2 THEN 10 ELSE 0 END) DESC LIMIT 100) AS temp INNER JOIN Users AS u ON temp.OwnerUserId = u.Id
|
### Instruction:
Most popular GIS tags in June 2015.
### Response:
|
SELECT num.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS MayRank, ROW_NUMBER() OVER (ORDER BY num.Num DESC) AS TotalRank, rate.Rate AS QuestionsInMay, num.Num AS QuestionsTotal FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate < '2015-07-01' AND Posts.CreationDate > '2015-06-01' GROUP BY TagName) AS rate INNER JOIN (SELECT COUNT(PostId) AS Num, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId GROUP BY TagName HAVING COUNT(PostId) > 800) AS num ON rate.TagName = num.TagName ORDER BY rate.rate DESC
|
### Instruction:
Retrieve Suggested Tags Based on 4 tags. Meta query for: http://meta.stackoverflow.com/questions/271397/tag-combinations-that-suggest-re-tagging-automatically
### Response:
|
SELECT * FROM Tags WHERE TagName LIKE (@Tag1 + '-' + @Tag2) OR TagName LIKE (@Tag1 + '-' + @Tag3) OR TagName LIKE (@Tag1 + '-' + @Tag4) OR TagName LIKE (@Tag2 + '-' + @Tag1) OR TagName LIKE (@Tag2 + '-' + @Tag3) OR TagName LIKE (@Tag2 + '-' + @Tag4) OR TagName LIKE (@Tag3 + '-' + @Tag1) OR TagName LIKE (@Tag3 + '-' + @Tag2) OR TagName LIKE (@Tag3 + '-' + @Tag4) OR TagName LIKE (@Tag4 + '-' + @Tag1) OR TagName LIKE (@Tag4 + '-' + @Tag2) OR TagName LIKE (@Tag4 + '-' + @Tag3)
|
### Instruction:
what is the fare for a one way flight from BOSTON to ATLANTA
### Response:
|
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ATLANTA' AND fare.round_trip_required = 'NO' AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
|
### Instruction:
Most popular StackOverflow tags in October 2012.
### Response:
|
SELECT num.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS MayRank, ROW_NUMBER() OVER (ORDER BY num.Num DESC) AS TotalRank, rate.Rate AS QuestionsInMay, num.Num AS QuestionsTotal FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate < '2012-06-01' AND Posts.CreationDate > '2012-06-30' GROUP BY TagName) AS rate INNER JOIN (SELECT COUNT(PostId) AS Num, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId GROUP BY TagName HAVING COUNT(PostId) > 800) AS num ON rate.TagName = num.TagName ORDER BY rate.rate DESC
|
### Instruction:
what is the name of the procedure that has been done two or more times in 01/last year to patient 61003?
### Response:
|
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT t1.icd9_code FROM (SELECT procedures_icd.icd9_code, COUNT(procedures_icd.charttime) AS c1 FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 61003) AND DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', procedures_icd.charttime) = '01' GROUP BY procedures_icd.icd9_code) AS t1 WHERE t1.c1 >= 2)
|
### Instruction:
i'd like a flight from KANSAS CITY to LOS ANGELES that arrives in LOS ANGELES in the late afternoon
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE ((flight.arrival_time <= 1800 AND flight.arrival_time >= 1600) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'LOS ANGELES' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'KANSAS CITY' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
when was the last time that patient 016-35481 was prescribed dextrose and nss infusion at the same time?
### Response:
|
SELECT t1.drugstarttime FROM (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'dextrose' AND patient.uniquepid = '016-35481') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'nss infusion' AND patient.uniquepid = '016-35481') AS t2 ON t1.uniquepid = t2.uniquepid WHERE DATETIME(t1.drugstarttime) = DATETIME(t2.drugstarttime) ORDER BY t1.drugstarttime DESC LIMIT 1
|
### Instruction:
JavaScript MVC Framework Trends (from TodoMVC) (# of Questions per Month).
### Response:
|
SELECT DATEADD(mm, (YEAR(2017) - 1900) * 12 + MONTH(Posts.CreationDate) - 1, 0) AS Month, Tags.TagName, COUNT(*) AS Questions FROM Tags LEFT JOIN PostTags ON PostTags.TagId = Tags.Id LEFT JOIN Posts ON Posts.Id = PostTags.PostId LEFT JOIN PostTypes ON PostTypes.Id = Posts.PostTypeId WHERE Tags.TagName IN ('backbone.js', 'ember.js', 'knockout.js', 'dojo', 'polymer', 'reactjs', 'kendo-ui', 'extjs', 'angularjs') AND PostTypes.Name = 'Question' GROUP BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName ORDER BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName
|
### Instruction:
Find number of answers per month since 2012 for Trusted Users.
### Response:
|
SELECT u.Id, u.Reputation, u.DisplayName, TIME_TO_STR(p.CreationDate, '%YEAR') AS Year, TIME_TO_STR(p.CreationDate, '%-mONT%-H') AS Month, COUNT(*) AS Count FROM Users AS u INNER JOIN Posts AS p ON u.Id = p.OwnerUserId WHERE TIME_TO_STR(p.CreationDate, '%Year') >= 2012 AND TIME_TO_STR(p.CreationDate, '%Year') < 2013 AND p.PostTypeId = 2 AND u.Reputation >= 20000 GROUP BY u.Id, u.Reputation, u.DisplayName, TIME_TO_STR(p.CreationDate, '%YEAR'), TIME_TO_STR(p.CreationDate, '%-mONT%-H') ORDER BY -Reputation, u.Id, Year, Month
|
### Instruction:
when is the last time patient 24921 has had tpn d11.0 on 09/20/last year?
### Response:
|
SELECT inputevents_cv.charttime FROM inputevents_cv WHERE inputevents_cv.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 24921)) AND inputevents_cv.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'tpn d11.0' AND d_items.linksto = 'inputevents_cv') AND DATETIME(inputevents_cv.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m-%d', inputevents_cv.charttime) = '09-20' ORDER BY inputevents_cv.charttime DESC LIMIT 1
|
### Instruction:
How many users have I helped?. A count of the unique users who have accepted one of a user's answers.
(Excludes the user accepting their own answers)
### Response:
|
SELECT COUNT(a.Id) AS "total_answers", COUNT(DISTINCT q.OwnerUserId) AS "unique_users", SUM(CASE WHEN q.AcceptedAnswerId = a.Id THEN 1 ELSE 0 END) AS "accepted_answers", COUNT(DISTINCT CASE WHEN q.AcceptedAnswerId = a.Id THEN q.OwnerUserId END) AS "unique_users_who_accepted", SUM(q.ViewCount) AS "estimate_views_of_answers", SUM(CASE WHEN q.AcceptedAnswerId = a.Id THEN q.ViewCount ELSE 0 END) AS "estimate_views_of_accepted_answers" FROM Posts AS q INNER JOIN Posts AS a ON a.ParentId = q.Id WHERE a.OwnerUserId = '##UserId##' AND q.OwnerUserId != '##UserId##'
|
### Instruction:
what has changed in weight of patient 007-8317 second measured on the first hospital visit compared to the value first measured on the first hospital visit?
### Response:
|
SELECT (SELECT patient.admissionweight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '007-8317' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1) AND NOT patient.admissionweight IS NULL ORDER BY patient.unitadmittime LIMIT 1 OFFSET 1) - (SELECT patient.admissionweight FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '007-8317' AND NOT patient.hospitaldischargetime IS NULL ORDER BY patient.hospitaladmittime LIMIT 1) AND NOT patient.admissionweight IS NULL ORDER BY patient.unitadmittime LIMIT 1)
|
### Instruction:
Users with the most Zero score Answers.
### Response:
|
SELECT U.Id AS "user_link", (SELECT COUNT(P.Id) FROM Posts AS P, PostTypes AS Pt, PostHistory AS Ph, PostHistoryTypes AS Pht WHERE U.Id = P.OwnerUserId AND P.Id = Ph.PostId AND Pt.Id = P.PostTypeId AND Pt.Id = 2 AND Pht.Id = Ph.PostHistoryTypeId AND Pht.Id = 2 AND P.Score = 0) AS "zeroes" FROM Users AS U WHERE (SELECT COUNT(P.Id) FROM Posts AS P, PostTypes AS Pt, PostHistory AS Ph, PostHistoryTypes AS Pht WHERE U.Id = P.OwnerUserId AND P.Id = Ph.PostId AND Pt.Id = P.PostTypeId AND Pt.Id = 2 AND Pht.Id = Ph.PostHistoryTypeId AND Pht.Id = 2 AND P.Score = 0) > 1000 ORDER BY ZEROES DESC
|
### Instruction:
Posts tagged language by location and view count.
### Response:
|
SELECT Posts.Id, Posts.CreationDate, Posts.Tags, Posts.ViewCount, Users.Id, Users.Reputation, Users.Location FROM Posts LEFT JOIN Users ON Users.Id = Posts.OwnerUserId WHERE DATALENGTH(Posts.Title) > 0 AND DATALENGTH(Users.Location) > 0 AND Posts.CreationDate >= '2014-01-01T00:00:00.000' AND Posts.CreationDate <= '2015-07-06T00:00:00.000' AND Posts.Tags IN (SELECT Posts.Tags FROM Posts WHERE Posts.Tags LIKE '%ruby%' OR Posts.Tags LIKE '%php%' OR Posts.Tags LIKE '%python%' OR Posts.Tags LIKE '%javascript%' OR Posts.Tags LIKE '%MEAN%' OR Posts.Tags LIKE '%LAMP%' OR Posts.Tags LIKE '%rails%')
|
### Instruction:
indicate the daily minimum arterial bp mean of patient 13622 in 08/last year.
### Response:
|
SELECT MIN(chartevents.valuenum) FROM chartevents WHERE chartevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 13622)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'arterial bp mean' AND d_items.linksto = 'chartevents') AND DATETIME(chartevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', chartevents.charttime) = '08' GROUP BY STRFTIME('%y-%m-%d', chartevents.charttime)
|
### Instruction:
Most popular StackOverflow tags in 2017.
### Response:
|
SELECT num.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS MayRank, ROW_NUMBER() OVER (ORDER BY num.Num DESC) AS TotalRank, rate.Rate AS QuestionsInMay, num.Num AS QuestionsTotal FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate < '2017-11-02' AND Posts.CreationDate > '2009-01-01' GROUP BY TagName) AS rate INNER JOIN (SELECT COUNT(PostId) AS Num, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId GROUP BY TagName HAVING COUNT(PostId) > 100) AS num ON rate.TagName = num.TagName ORDER BY rate.rate DESC
|
### Instruction:
what is the daily minimum of output (ml)-chest tube right lateral output of patient 015-59552 in 12/this year?
### Response:
|
SELECT MIN(intakeoutput.cellvaluenumeric) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '015-59552')) AND intakeoutput.celllabel = 'output (ml)-chest tube right lateral' AND intakeoutput.cellpath LIKE '%output%' AND DATETIME(intakeoutput.intakeoutputtime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', intakeoutput.intakeoutputtime) = '12' GROUP BY STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime)
|
### Instruction:
show me round trip fares from PITTSBURGH to PHILADELPHIA
### Response:
|
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PITTSBURGH' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHILADELPHIA' AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
|
### Instruction:
what is the number of hours elapsed since the first time patient 007-15837 had a intake (ml)-gastrostomy/enterostomy gastrostomy 20 fr. luq intake on the current icu visit?
### Response:
|
SELECT 24 * (STRFTIME('%j', CURRENT_TIME()) - STRFTIME('%j', intakeoutput.intakeoutputtime)) FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '007-15837') AND patient.unitdischargetime IS NULL) AND intakeoutput.celllabel = 'intake (ml)-gastrostomy/enterostomy gastrostomy 20 fr. luq' AND intakeoutput.cellpath LIKE '%intake%' ORDER BY intakeoutput.intakeoutputtime LIMIT 1
|
### Instruction:
review stats for each review queue.
### Response:
|
SELECT CASE ReviewTaskTypeId WHEN 1 THEN 'Suggested edits' WHEN 2 THEN 'Close Votes' WHEN 3 THEN 'Low Quality Posts' WHEN 4 THEN 'First Posts' WHEN 5 THEN 'Late Answers' WHEN 6 THEN 'Reopen Votes' WHEN 7 THEN 'Community Evaluation' WHEN 8 THEN 'Link Validation' WHEN 9 THEN 'Flagged Posts' WHEN 10 THEN 'Triage' WHEN 11 THEN 'Helper' ELSE 'Unknown' END AS reviewtype, COUNT(*) AS totalreviews, SUM(CASE WHEN ReviewTaskResultTypeId = 1 THEN 1 ELSE 0 END) AS skipped, CAST(SUM(CASE WHEN ReviewTaskResultTypeId = 1 THEN 1 ELSE 0 END) AS FLOAT(18, 9)) / COUNT(*) AS skiprate FROM ReviewTaskResults AS rr INNER JOIN ReviewTasks AS rt ON rt.Id = rr.ReviewTaskId GROUP BY ReviewTaskTypeId
|
### Instruction:
what was the first value of the arterial bp [diastolic] of patient 27703 on last month/02?
### Response:
|
SELECT chartevents.valuenum FROM chartevents WHERE chartevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 27703)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'arterial bp [diastolic]' AND d_items.linksto = 'chartevents') AND DATETIME(chartevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') AND STRFTIME('%d', chartevents.charttime) = '02' ORDER BY chartevents.charttime LIMIT 1
|
### Instruction:
A User Rank In A Given Tag.
### Response:
|
SELECT T2.Rank, T2.Id AS "user_link", T2.UpVotes AS "total_up_votes" FROM (SELECT ROW_NUMBER() OVER (ORDER BY T.UpVotes DESC) AS Rank, T.Id, T.UpVotes FROM (SELECT u.Id, COUNT(*) AS UpVotes FROM Tags AS t WITH (nolock) INNER JOIN PostTags AS pt WITH (nolock) ON pt.TagId = t.Id INNER JOIN Posts AS p WITH (nolock) ON p.ParentId = pt.PostId INNER JOIN Votes AS v WITH (nolock) ON v.PostId = p.Id AND v.VoteTypeId = 2 INNER JOIN Users AS u WITH (nolock) ON u.Id = p.OwnerUserId WHERE p.CommunityOwnedDate IS NULL AND t.TagName = @TagName GROUP BY u.Id ORDER BY UpVotes DESC) AS T) AS T2 WHERE T2.Id = @UserId
|
### Instruction:
show me flights from PHILADELPHIA to SAN FRANCISCO on WEDNESDAY
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND days.day_name = 'WEDNESDAY' AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PHILADELPHIA' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
edit review queue size by week.
### Response:
|
SELECT DATEADD(week, DATEDIFF(week, '2000-01-01 00:00:00', sampledate), '2000-01-01 00:00:00') AS sampleweek, MAX(queuesize) AS maxqueuesize, MIN(queuesize) AS minqueuesize FROM (SELECT ref.CreationDate AS sampledate, COUNT(*) AS queuesize FROM SuggestedEdits AS ref INNER JOIN SuggestedEdits AS s ON (s.CreationDate <= ref.CreationDate AND (COALESCE(s.ApprovalDate, s.RejectionDate) IS NULL OR COALESCE(s.ApprovalDate, s.RejectionDate) > ref.CreationDate)) GROUP BY ref.CreationDate) AS x GROUP BY DATEDIFF(week, '2000-01-01 00:00:00', sampledate) ORDER BY sampleweek
|
### Instruction:
list flights between BOSTON and SAN FRANCISCO that serve BREAKFAST
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight, food_service WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code AND food_service.meal_code = flight.meal_code AND food_service.meal_description = 'BREAKFAST') AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
what is the name of the treatment that patient 12938 had been given two times in 03/last year?
### Response:
|
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT t1.icd9_code FROM (SELECT procedures_icd.icd9_code, COUNT(procedures_icd.charttime) AS c1 FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 12938) AND DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m', procedures_icd.charttime) = '03' GROUP BY procedures_icd.icd9_code) AS t1 WHERE t1.c1 = 2)
|
### Instruction:
Users with sufficient score and number of answers for a tag badge.
### Response:
|
WITH scorestags_cte AS (SELECT pt.TagId AS TagId, p.OwnerUserId AS uid, p.OwnerDisplayName AS udn, SUM(p.Score) AS sco, COUNT(p.Id) AS num FROM Posts AS p INNER JOIN Posts AS q ON q.Id = p.ParentId INNER JOIN PostTags AS pt ON q.Id = pt.PostId WHERE (p.CommunityOwnedDate IS NULL) GROUP BY pt.TagId, p.OwnerUserId, p.OwnerDisplayName) SELECT t.TagName, s.uid AS "user_link", s.udn, s.sco AS "score", s.num AS "count" FROM scorestags_cte AS s INNER JOIN Tags AS t ON s.TagId = t.Id WHERE (s.sco >= '##minsco?100##') AND (s.num >= '##mincount?20##') ORDER BY s.sco DESC
|
### Instruction:
This query shows all answer posts which are relevant for the 'Unsung Hero' badge sorted by the creation date. In addition it shows if a post is already counting (older than 10 days) or not.. This query shows all answer posts which are relevant for the 'Unsung Hero' badge sorted by the creation date. In addition it shows if a post is already counting (older than 10 days) or not.
### Response:
|
SELECT a.Id AS "post_link", a.CreationDate AS "answer_creation_date", (CASE WHEN DATEDIFF(dd, a.CreationDate, GETDATE()) < 10 THEN 0 ELSE 1 END) AS "10_days_criterion_met" FROM Posts AS q INNER JOIN Posts AS a ON a.Id = q.AcceptedAnswerId WHERE a.CommunityOwnedDate IS NULL AND a.OwnerUserId = @UserId AND q.OwnerUserId != @UserId AND a.PostTypeId = 2 AND a.Score = 0 ORDER BY a.CreationDate DESC
|
### Instruction:
-- Most popular StackOverflow tags in May 2019.
### Response:
|
SELECT num.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS Rank, ROW_NUMBER() OVER (ORDER BY num.Num DESC) AS TotalRank, rate.Rate AS Questions, num.Num AS QuestionsTotal FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate < '2019-12-31' AND Posts.CreationDate > '2019-01-01' GROUP BY TagName) AS rate INNER JOIN (SELECT COUNT(PostId) AS Num, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId GROUP BY TagName HAVING COUNT(PostId) > 800) AS num ON rate.TagName = num.TagName ORDER BY rate.rate DESC
|
### Instruction:
Top Spring points in the bay area. Top Spring points in the bay area
### Response:
|
SELECT u.Id, (SELECT DisplayName FROM Users AS udn WITH (nolock) WHERE udn.Id = u.Id), (SELECT AboutMe FROM Users AS udn WITH (nolock) WHERE udn.Id = u.Id), COUNT(*) AS UpVotes FROM Tags AS t WITH (nolock) INNER JOIN PostTags AS pt WITH (nolock) ON pt.TagId = t.Id INNER JOIN Posts AS p WITH (nolock) ON p.ParentId = pt.PostId INNER JOIN Votes AS v WITH (nolock) ON v.PostId = p.Id AND v.VoteTypeId = 2 INNER JOIN Users AS u WITH (nolock) ON u.Id = p.OwnerUserId WHERE p.CommunityOwnedDate IS NULL AND t.TagName = 'django' AND u.Location LIKE '%NY%' OR u.Location LIKE '%New York%' GROUP BY u.Id ORDER BY UpVotes DESC LIMIT 100
|
### Instruction:
How Many Top 1000 Users according to Average Question Score in the Real Top 1000.
### Response:
|
WITH TT AS (SELECT Users.Id AS Id, Users.Reputation AS UserReputation, COUNT(Posts.Id) AS Questions, CAST(AVG(CAST(Score AS FLOAT)) AS FLOAT(6, 2)) AS "average_question_score" FROM Posts INNER JOIN Users ON Users.Id = OwnerUserId WHERE PostTypeId = 1 AND CommunityOwnedDate IS NULL AND ClosedDate IS NULL GROUP BY Users.Id, DisplayName, Users.Reputation HAVING COUNT(Posts.Id) > 10 ORDER BY 'average_question_score' DESC LIMIT 1000) SELECT TT.Id AS "user_link", Users.Reputation AS UserReputation, 'average_question_score' FROM TT INNER JOIN Users ON Users.Id = TT.Id WHERE Users.Reputation > 69869 ORDER BY UserReputation DESC
|
### Instruction:
Post and Answer counts per user with reputation.
### Response:
|
WITH qs AS (SELECT COUNT(p.Id) AS "NumQuestion", u.Id, u.DisplayName, u.Reputation FROM Posts AS p JOIN Users AS u ON p.OwnerUserId = u.Id WHERE p.PostTypeId = 1 AND u.Reputation > 10 GROUP BY u.Id, u.Reputation, u.DisplayName, p.PostTypeId), ans AS (SELECT COUNT(p.Id) AS "NumAnswer", u.Id FROM Posts AS p JOIN Users AS u ON p.OwnerUserId = u.Id WHERE p.PostTypeId = 2 AND u.Reputation > 10 GROUP BY u.Id, u.Reputation, u.DisplayName, p.PostTypeId) SELECT COALESCE(NumQuestion, 0) AS NumQuestion, COALESCE(NumAnswer, 0) AS NumAnswer, qs.Id, DisplayName, Reputation FROM qs FULL OUTER JOIN ans ON qs.Id = ans.Id
|
### Instruction:
JavaScript Trends (# of Questions per Month).
### Response:
|
SELECT DATEADD(mm, (YEAR(Posts.CreationDate) - 1900) * 12 + MONTH(Posts.CreationDate) - 1, 0) AS Month, Tags.TagName, COUNT(*) AS Questions FROM Tags LEFT JOIN PostTags ON PostTags.TagId = Tags.Id LEFT JOIN Posts ON Posts.Id = PostTags.PostId LEFT JOIN PostTypes ON PostTypes.Id = Posts.PostTypeId WHERE Tags.TagName IN ('angularjs', 'backbone.js', 'ember.js', 'meteor', 'reactjs') AND PostTypes.Name = 'Question' AND Posts.CreationDate < DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) GROUP BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName ORDER BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName
|
### Instruction:
sequence 1, 2, 3, 3, 2, 1....
### Response:
|
WITH numbers(x) AS (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) FROM (VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0)) AS n0(x) CROSS JOIN (VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0)) AS n1(x) CROSS JOIN (VALUES (0), (0), (0), (0), (0), (0), (0), (0), (0), (0)) AS n2(x)) SELECT x, x % (2 * @n) + (1 - 2 * (x % @n)) * (((x - 1) / @n) % 2) FROM (SELECT TOP(2 * @n * @m) AS x FROM numbers) AS v(x) ORDER BY x
|
### Instruction:
Most popular tag's during a certain period..
### Response:
|
SELECT num.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS MayRank, ROW_NUMBER() OVER (ORDER BY num.Num DESC) AS TotalRank, rate.Rate AS QuestionsInMay, num.Num AS QuestionsTotal FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate < '2019-06-01' AND Posts.CreationDate > '2019-05-01' GROUP BY TagName) AS rate INNER JOIN (SELECT COUNT(PostId) AS Num, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId GROUP BY TagName HAVING COUNT(PostId) > 800) AS num ON rate.TagName = num.TagName ORDER BY rate.rate DESC
|
### Instruction:
most used tags in 2014.
### Response:
|
SELECT num.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS MayRank, ROW_NUMBER() OVER (ORDER BY num.Num DESC) AS TotalRank, rate.Rate AS QuestionsInMay, num.Num AS QuestionsTotal FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate < '2014-12-31' AND Posts.CreationDate > '2014-01-01' GROUP BY TagName) AS rate INNER JOIN (SELECT COUNT(PostId) AS Num, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId GROUP BY TagName HAVING COUNT(PostId) > 800) AS num ON rate.TagName = num.TagName ORDER BY rate.rate DESC
|
### Instruction:
Most popular StackOverflow tags in May 2016.
### Response:
|
SELECT num.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS OctRank, ROW_NUMBER() OVER (ORDER BY num.Num DESC) AS TotalRank, rate.Rate AS QuestionsInOct, num.Num AS QuestionsTotal FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate < '2016-10-26' AND Posts.CreationDate > '2016-9-26' GROUP BY TagName) AS rate INNER JOIN (SELECT COUNT(PostId) AS Num, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId GROUP BY TagName HAVING COUNT(PostId) > 1) AS num ON rate.TagName = num.TagName ORDER BY rate.rate DESC
|
### Instruction:
show me a list of flights from BOSTON to ATLANTA leaving after 1200 and arriving before 1900
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE ((flight.arrival_time <= 1900 AND flight.departure_time > 1200) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'ATLANTA' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
Content removed from posts by other users.
### Response:
|
SELECT p.Id AS "post_link", h2.CreationDate AS "Removed on", h2.UserId AS "user_link", h2.Comment AS "Edit summary" FROM PostHistory AS h1 INNER JOIN Posts AS p ON h1.PostId = p.Id JOIN LATERAL (SELECT Text, UserId, CreationDate, Comment FROM PostHistory WHERE PostId = h1.PostId AND PostHistoryTypeId = 5 AND CreationDate > h1.CreationDate ORDER BY CreationDate LIMIT 1) AS h2 WHERE h1.CreationDate >= '##dateFrom:string##' AND h1.Text LIKE '%' + '##query:string##' + '%' AND h1.PostHistoryTypeId IN (2, 5) AND NOT h2.Text LIKE '%' + '##query:string##' + '%' AND (h2.UserId != p.OwnerUserId OR h2.UserId IS NULL) ORDER BY h2.CreationDate DESC
|
### Instruction:
Rolling 30 day > 30 question user count.
### Response:
|
WITH DayPosts AS (SELECT OwnerUserId, CreationDate, COUNT(*) AS PostCount, ROW_NUMBER() OVER (PARTITION BY OwnerUserId ORDER BY CreationDate) AS Num FROM Posts WHERE PostTypeId = 1 GROUP BY OwnerUserId, CreationDate), UserMonths AS (SELECT OwnerUserId, CreationDate, PostCount, Num FROM DayPosts UNION ALL SELECT DayPosts.OwnerUserId, UserMonths.CreationDate, DayPosts.PostCount + UserMonths.PostCount, DayPosts.Num FROM DayPosts INNER JOIN UserMonths ON DayPosts.OwnerUserId = UserMonths.OwnerUserId AND DayPosts.Num = UserMonths.Num + 1 AND DATEDIFF(dd, UserMonths.CreationDate, CreationDate) BETWEEN 1 AND 30) SELECT COUNT(DISTINCT OwnerUserId) FROM UserMonths WHERE PostCount > 30
|
### Instruction:
tell me the difference between the total amount of input and the total output of patient 18457 on the last intensive care unit visit?
### Response:
|
SELECT (SELECT SUM(inputevents_cv.amount) FROM inputevents_cv WHERE inputevents_cv.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 18457) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime DESC LIMIT 1)) - (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 = 18457) AND NOT icustays.outtime IS NULL ORDER BY icustays.intime DESC LIMIT 1))
|
### Instruction:
Posts from engineers at big companies.
### Response:
|
SELECT U.profile_url, U.Reputation, PL.PostId AS "post_link", * FROM (SELECT ('http://stackoverflow.com/users/' + CAST(Id AS TEXT)) AS profile_url, Reputation, Id FROM Users WHERE (LOWER(AboutMe) LIKE '%1and1%') AND Reputation > 1000 LIMIT 800) AS U JOIN Posts AS P ON P.OwnerUserId = U.Id JOIN PostLinks AS PL ON PL.PostId = P.Id JOIN PostTags AS PT ON PT.PostId = P.Id JOIN Tags AS T ON T.Id = PT.TagId AND T.TagName IN ('algorithm', 'math', 'combinatorics', 'graph-theory', 'matrix', 'data-structures', 'language-agnostic', 'performance', 'geometry', 'linear-algebra', 'algebra', 'bitvector', 'bit-manipulation', 'permutation', 'optimization') LIMIT 1000
|
### Instruction:
list aircraft types that fly between BOSTON and SAN FRANCISCO
### Response:
|
SELECT DISTINCT aircraft.aircraft_code FROM aircraft, airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, equipment_sequence, flight WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BOSTON' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND equipment_sequence.aircraft_code = aircraft.aircraft_code AND flight.aircraft_code_sequence = equipment_sequence.aircraft_code_sequence AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
|
### Instruction:
how many DAILY US flights are there between PHILADELPHIA and PITTSBURGH
### Response:
|
SELECT COUNT(DISTINCT flight.flight_id) FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE ((CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PHILADELPHIA' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PITTSBURGH' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND flight.airline_code = 'US') AND flight.flight_days = 'DAILY'
|
### Instruction:
what is the cost for these flights from BALTIMORE to PHILADELPHIA
### Response:
|
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'BALTIMORE' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PHILADELPHIA' AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
|
### Instruction:
when was the last arterial bp [diastolic] of patient 25814 measured on this month/28?
### Response:
|
SELECT chartevents.charttime FROM chartevents WHERE chartevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 25814)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'arterial bp [diastolic]' AND d_items.linksto = 'chartevents') AND DATETIME(chartevents.charttime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-0 month') AND STRFTIME('%d', chartevents.charttime) = '28' ORDER BY chartevents.charttime DESC LIMIT 1
|
### Instruction:
Question Single Vote Closures by User & Reason.
### Response:
|
WITH superclosures AS (SELECT ph.Id, ph.PostId AS "post_link", u.DisplayName AS CloseUser, crt.Name AS CloseReasonType, COUNT(v.value) AS VoterCount FROM PostHistory AS ph JOIN Posts AS p ON p.Id = ph.PostId JOIN Users AS u ON u.Id = ph.UserId JOIN CloseReasonTypes AS crt ON crt.Id = ph.Comment JOIN LATERAL OPENJSON(ph.Text, '$.Voters') AS v WHERE PostHistoryTypeId = 10 AND p.PostTypeId = 1 AND u.DisplayName != 'Community' GROUP BY ph.Id, ph.PostId, ph.Comment, u.DisplayName, crt.Name HAVING COUNT(v.value) = 1) SELECT CloseUser, CloseReasonType, COUNT(*) AS Closures FROM superclosures GROUP BY CloseUser, CloseReasonType ORDER BY CloseUser, COUNT(*) DESC
|
### Instruction:
Questions with (likely) uninformative titles answered by a user.
### Response:
|
SELECT q.Id AS "post_link", q.Tags FROM Posts AS q INNER JOIN Posts AS a ON a.ParentId = q.Id WHERE a.OwnerUserId = '##UserId##' AND (q.Title LIKE '%anyone%' OR q.Title LIKE '%difficult%' OR q.Title LIKE '%doubt%' OR q.Title LIKE '%easy%' OR q.Title LIKE '%exercise%' OR q.Title LIKE '%hard%' OR q.Title LIKE '%help%' OR q.Title LIKE '%homework%' OR q.Title LIKE '%interesting%' OR q.Title LIKE '% math%' OR q.Title LIKE '%please%' OR q.Title LIKE '%problem%' OR q.Title LIKE '%question%' OR q.Title LIKE '%someone%' OR q.Title LIKE '%struggl%' OR q.Title LIKE '%stuck%' OR q.Title LIKE '% very%' OR q.Title LIKE '%wrong%') ORDER BY a.CreationDate DESC
|
### Instruction:
PostgreSQL quadratic scoring for Related Tags. The 'Top 20 topics' for PostgreSQL commity investment in new issues. Need to be filtered (to drop language tags, etc.). Filtered top results example: psql, plpgsql, json, postgis, arrays, jsonb, etc.
PS: gets the most commonly associated tags to the PostgreSQL tags, by number of posts
### Response:
|
SELECT * FROM (SELECT t1.TagName, ROUND(SQRT(COUNT(*)), 0) AS upVotes_score FROM (SELECT Tags.TagName, PostId FROM PostTags INNER JOIN Tags ON Tags.Id = PostTags.TagId WHERE PostTags.PostId IN (SELECT DISTINCT PostId FROM PostTags INNER JOIN Tags ON Tags.Id = PostTags.TagId WHERE Tags.TagName LIKE 'postgresql%') AND NOT (Tags.TagName LIKE 'postgresql%')) AS t1 INNER JOIN Votes ON Votes.PostId = t1.PostId AND Votes.VoteTypeId = 2 GROUP BY TagName) AS t2
|
### Instruction:
what was the name of the procedure that patient 17638 received two times in 06/this year.
### Response:
|
SELECT d_icd_procedures.short_title FROM d_icd_procedures WHERE d_icd_procedures.icd9_code IN (SELECT t1.icd9_code FROM (SELECT procedures_icd.icd9_code, COUNT(procedures_icd.charttime) AS c1 FROM procedures_icd WHERE procedures_icd.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 17638) AND DATETIME(procedures_icd.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m', procedures_icd.charttime) = '06' GROUP BY procedures_icd.icd9_code) AS t1 WHERE t1.c1 = 2)
|
### Instruction:
all right what US flights leave from INDIANAPOLIS to SAN DIEGO after 1330 in the afternoon
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE ((CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN DIEGO' AND flight.departure_time > 1330 AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'INDIANAPOLIS' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'US'
|
### Instruction:
show me all flights from DENVER to PITTSBURGH which serve DINNER
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight, food_service WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PITTSBURGH' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code AND food_service.meal_code = flight.meal_code AND food_service.meal_description = 'DINNER') AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'DENVER' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
when did patient 021-141335 the last time had urinary catheter output: indwelling/continuous ure output on last month/05?
### Response:
|
SELECT intakeoutput.intakeoutputtime FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '021-141335')) AND intakeoutput.cellpath LIKE '%output%' AND intakeoutput.celllabel = 'urinary catheter output: indwelling/continuous ure' AND DATETIME(intakeoutput.intakeoutputtime, 'start of month') = DATETIME(CURRENT_TIME(), 'start of month', '-1 month') AND STRFTIME('%d', intakeoutput.intakeoutputtime) = '05' ORDER BY intakeoutput.intakeoutputtime DESC LIMIT 1
|
### Instruction:
when was last time the systemicdiastolic of patient 018-119251 was greater than 41.0 on 04/15/this year?
### Response:
|
SELECT vitalperiodic.observationtime FROM vitalperiodic WHERE vitalperiodic.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '018-119251')) AND vitalperiodic.systemicdiastolic > 41.0 AND NOT vitalperiodic.systemicdiastolic IS NULL AND DATETIME(vitalperiodic.observationtime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-0 year') AND STRFTIME('%m-%d', vitalperiodic.observationtime) = '04-15' ORDER BY vitalperiodic.observationtime DESC LIMIT 1
|
### Instruction:
when for the last time patient 005-87465 has had evd output (ml)-icp/external ventricular drain (evd) left ventriculostomy output since 05/06/2104?
### Response:
|
SELECT intakeoutput.intakeoutputtime FROM intakeoutput WHERE intakeoutput.patientunitstayid IN (SELECT patient.patientunitstayid FROM patient WHERE patient.patienthealthsystemstayid IN (SELECT patient.patienthealthsystemstayid FROM patient WHERE patient.uniquepid = '005-87465')) AND intakeoutput.cellpath LIKE '%output%' AND intakeoutput.celllabel = 'evd output (ml)-icp/external ventricular drain (evd) left ventriculostomy' AND STRFTIME('%y-%m-%d', intakeoutput.intakeoutputtime) >= '2104-05-06' ORDER BY intakeoutput.intakeoutputtime DESC LIMIT 1
|
### Instruction:
how many patients underwent oxygen therapy (40% to 60%) within 2 months after they were diagnosed with pneumonia?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'pneumonia') AS t1 JOIN (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'oxygen therapy (40% to 60%)') AS t2 WHERE t1.diagnosistime < t2.treatmenttime AND DATETIME(t2.treatmenttime) BETWEEN DATETIME(t1.diagnosistime) AND DATETIME(t1.diagnosistime, '+2 month')
|
### Instruction:
Users with reputation > 10000 and < 50 answers.
### Response:
|
SELECT Users.Id AS "user_link", Users.DisplayName, Users.Reputation, SUM(CASE WHEN Posts.PostTypeId = 1 THEN 1 ELSE 0 END) AS Questions, SUM(CASE WHEN Posts.PostTypeId = 2 THEN 1 ELSE 0 END) AS Answers, Users.UpVotes, Users.DownVotes FROM Users INNER JOIN Posts ON Users.Id = Posts.OwnerUserId AND (Posts.PostTypeId = 1 OR Posts.PostTypeId = 2) AND Users.Reputation > 10000 GROUP BY Users.Id, Users.CreationDate, Users.LastAccessDate, Users.Reputation, Users.DisplayName, Users.CreationDate, Users.Views, Users.UpVotes, Users.DownVotes HAVING SUM(CASE WHEN Posts.PostTypeId = 2 THEN 1 ELSE 0 END) < 50 ORDER BY Users.Id
|
### Instruction:
can you tell me the afternoon nonstop flights departing from ATLANTA to BOSTON
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE (((flight.departure_time BETWEEN 1200 AND 1800) AND (flight.stops = 0)) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BOSTON' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'ATLANTA' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
Votes on older posts by month.
### Response:
|
SELECT DATEFROMPARTS(Year, Month, 1), 100 * ROUND(Votes * 1.0 / Answers, 2) AS Perf FROM (SELECT *, (SELECT COUNT(*) FROM Posts AS AllPosts WHERE AllPosts.OwnerUserId = '##UserId##' AND AllPosts.CreationDate <= DATEFROMPARTS(Year, Month, 1)) AS Answers FROM (SELECT DATEPART(YYYY, Votes.CreationDate) AS Year, DATEPART(MM, Votes.CreationDate) AS Month, COUNT(*) AS Votes FROM Votes INNER JOIN Posts ON Votes.PostId = Posts.Id WHERE Posts.OwnerUserId = '##UserId##' AND DATEDIFF(DD, Posts.CreationDate, CreationDate) > 30 GROUP BY DATEPART(YYYY, Votes.CreationDate), DATEPART(MM, Votes.CreationDate)) AS Raw) AS Raw ORDER BY Year, Month
|
### Instruction:
Churn Rate by User Join Date.
### Response:
|
SELECT churn.cYear, churn.cMonth, totalUsers, churn.churnUsers, (1.0 * churn.churnUsers / totalUsers) AS percentage FROM (SELECT YEAR(CreationDate) AS cYear, MONTH(CreationDate) AS cMonth, COUNT(Id) AS churnUsers FROM Users WHERE CreationDate < DATEADD(month, -'##months##', GETDATE()) AND DATEDIFF(month, CreationDate, LastAccessDate) < '##months##' GROUP BY YEAR(CreationDate), MONTH(CreationDate)) AS churn JOIN (SELECT YEAR(CreationDate) AS cYear, MONTH(CreationDate) AS cMonth, COUNT(Id) AS totalUsers FROM Users GROUP BY YEAR(CreationDate), MONTH(CreationDate)) AS total ON churn.cYear = total.cYear AND churn.cMonth = total.cMonth ORDER BY 1, 2
|
### Instruction:
i would like a flight from PHILADELPHIA to DALLAS arrive DALLAS about 12 noon
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE ((flight.arrival_time <= 1230 AND flight.arrival_time >= 1130) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'DALLAS' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'PHILADELPHIA' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
is there an early morning DL flight between BOSTON and WASHINGTON
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE (((flight.departure_time <= 0 AND flight.departure_time >= 800) AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'BOSTON' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'WASHINGTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code) AND flight.airline_code = 'DL'
|
### Instruction:
Number of posts in Stack Overflow that are over the 30k soft character limit.
### Response:
|
SELECT p.Id AS "post_link", (CASE WHEN p.PostTypeId = 1 THEN 'Q' ELSE 'A' END) AS Type, p.Id, LENGTH(p.Body) AS HtmlSize, LENGTH(ph.Text) AS MarkdownSize, p.CreationDate, ph.CreationDate AS LatestRevisionDate FROM Posts AS p INNER JOIN PostHistory AS ph ON ph.PostId = p.Id LEFT OUTER JOIN PostHistory AS phb ON phb.PostId = ph.PostId AND ph.CreationDate < phb.CreationDate WHERE (LENGTH(p.Body) > 30000 OR LENGTH(ph.Text) > 30000) AND ph.PostHistoryTypeId IN (2, 5, 8) AND phb.CreationDate IS NULL AND p.PostTypeId IN (1, 2) ORDER BY MarkdownSize DESC
|
### Instruction:
how many patients were diagnosed with headache - hydrocephalus within 2 months after having received a vte prophylaxis - compression stockings?
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'vte prophylaxis - compression stockings') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosistime FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'headache - hydrocephalus') AS t2 WHERE t1.treatmenttime < t2.diagnosistime AND DATETIME(t2.diagnosistime) BETWEEN DATETIME(t1.treatmenttime) AND DATETIME(t1.treatmenttime, '+2 month')
|
### Instruction:
the heart rate of patient 10624 was ever less than 75.0 on 09/04/last year?
### Response:
|
SELECT COUNT(*) > 0 FROM chartevents WHERE chartevents.icustay_id IN (SELECT icustays.icustay_id FROM icustays WHERE icustays.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 10624)) AND chartevents.itemid IN (SELECT d_items.itemid FROM d_items WHERE d_items.label = 'heart rate' AND d_items.linksto = 'chartevents') AND chartevents.valuenum < 75.0 AND DATETIME(chartevents.charttime, 'start of year') = DATETIME(CURRENT_TIME(), 'start of year', '-1 year') AND STRFTIME('%m-%d', chartevents.charttime) = '09-04'
|
### Instruction:
how many of the patients were diagnosed with cellulitis - chest within the same hospital visit after having received a analgesics - neuraxial analgesics procedure.
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, treatment.treatmenttime, patient.patienthealthsystemstayid FROM treatment JOIN patient ON treatment.patientunitstayid = patient.patientunitstayid WHERE treatment.treatmentname = 'analgesics - neuraxial analgesics') AS t1 JOIN (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'cellulitis - chest') AS t2 WHERE t1.treatmenttime < t2.diagnosistime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
|
### Instruction:
Most Popular Tags of 2018.
### Response:
|
SELECT num.TagName AS Tag, ROW_NUMBER() OVER (ORDER BY rate.Rate DESC) AS Rank, ROW_NUMBER() OVER (ORDER BY num.Num DESC) AS TotalRank, rate.Rate AS Questions, num.Num AS QuestionsTotal FROM (SELECT COUNT(PostId) AS Rate, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId AND Posts.CreationDate < '2018-03-09' AND Posts.CreationDate > '2017-12-31' GROUP BY TagName) AS rate INNER JOIN (SELECT COUNT(PostId) AS Num, TagName FROM Tags, PostTags, Posts WHERE Tags.Id = PostTags.TagId AND Posts.Id = PostId GROUP BY TagName HAVING COUNT(PostId) > 800) AS num ON rate.TagName = num.TagName ORDER BY rate.rate DESC
|
### Instruction:
Trello vs Jira (# of Question Views per Month).
### Response:
|
SELECT DATEADD(mm, (YEAR(Posts.CreationDate) - 1900) * 12 + MONTH(Posts.CreationDate) - 1, 0) AS Month, Tags.TagName, SUM(Posts.ViewCount) AS Views FROM Tags LEFT JOIN PostTags ON PostTags.TagId = Tags.Id LEFT JOIN Posts ON Posts.Id = PostTags.PostId LEFT JOIN PostTypes ON PostTypes.Id = Posts.PostTypeId WHERE Tags.TagName IN ('trello', 'jira') AND PostTypes.Name = 'Question' AND Posts.CreationDate < DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0) GROUP BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName ORDER BY YEAR(Posts.CreationDate), MONTH(Posts.CreationDate), Tags.TagName
|
### Instruction:
Java in-memory database popularity by time.
### Response:
|
SELECT d, SUM(h2) OVER (ORDER BY d) AS h2, SUM(hsqldb) OVER (ORDER BY d) AS hsqldb, SUM(derby) OVER (ORDER BY d) AS derby, SUM(sqlite) OVER (ORDER BY d) AS sqlite, SUM(firebird) OVER (ORDER BY d) AS firebird FROM (SELECT DATE(CreationDate) AS d, COUNT(CASE WHEN Tags LIKE '%<h2>%' THEN 1 END) AS h2, COUNT(CASE WHEN Tags LIKE '%<hsqldb>%' THEN 1 END) AS hsqldb, COUNT(CASE WHEN Tags LIKE '%<derby>%' THEN 1 END) AS derby, COUNT(CASE WHEN Tags LIKE '%<sqlite>%' THEN 1 END) AS sqlite, COUNT(CASE WHEN Tags LIKE '%<firebird>%' THEN 1 END) AS firebird FROM Posts GROUP BY DATE(CreationDate)) AS DailyPosts ORDER BY d
|
### Instruction:
show me the MONDAY flights from SAN FRANCISCO to PITTSBURGH
### Response:
|
SELECT DISTINCT flight.flight_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, days, flight WHERE (CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'PITTSBURGH' AND days.day_name = 'MONDAY' AND flight.flight_days = days.days_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'SAN FRANCISCO' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
show me all meals on flights from ATLANTA to WASHINGTON
### Response:
|
SELECT DISTINCT food_service.compartment, food_service.meal_code, food_service.meal_number FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight, food_service WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'ATLANTA' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'WASHINGTON' AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code AND food_service.meal_code = flight.meal_code
|
### Instruction:
how much does it cost to fly from ATLANTA to SAN FRANCISCO
### Response:
|
SELECT DISTINCT fare.fare_id FROM airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, fare, flight, flight_fare WHERE CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'ATLANTA' AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'SAN FRANCISCO' AND flight_fare.fare_id = fare.fare_id AND flight.flight_id = flight_fare.flight_id AND flight.from_airport = AIRPORT_SERVICE_0.airport_code AND flight.to_airport = AIRPORT_SERVICE_1.airport_code
|
### Instruction:
is mch of patient 7112 last measured on the current hospital visit less than the first value measured on the current hospital visit?
### Response:
|
SELECT (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 7112 AND admissions.dischtime IS NULL) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'mch') ORDER BY labevents.charttime DESC LIMIT 1) < (SELECT labevents.valuenum FROM labevents WHERE labevents.hadm_id IN (SELECT admissions.hadm_id FROM admissions WHERE admissions.subject_id = 7112 AND admissions.dischtime IS NULL) AND labevents.itemid IN (SELECT d_labitems.itemid FROM d_labitems WHERE d_labitems.label = 'mch') ORDER BY labevents.charttime LIMIT 1)
|
### Instruction:
oh let 's see does EA have a flight from ATLANTA to WASHINGTON
### Response:
|
SELECT DISTINCT airline.airline_code FROM airline, airport_service AS AIRPORT_SERVICE_0, airport_service AS AIRPORT_SERVICE_1, city AS CITY_0, city AS CITY_1, flight WHERE ((flight.airline_code = 'EA') AND CITY_1.city_code = AIRPORT_SERVICE_1.city_code AND CITY_1.city_name = 'WASHINGTON' AND flight.to_airport = AIRPORT_SERVICE_1.airport_code) AND CITY_0.city_code = AIRPORT_SERVICE_0.city_code AND CITY_0.city_name = 'ATLANTA' AND flight.airline_code = airline.airline_code AND flight.from_airport = AIRPORT_SERVICE_0.airport_code
|
### Instruction:
what are the three most commonly prescribed drugs for patients who were also prescribed ferrous sulfate at the same time?
### Response:
|
SELECT t3.drug FROM (SELECT t2.drug, DENSE_RANK() OVER (ORDER BY COUNT(*) DESC) AS c1 FROM (SELECT admissions.subject_id, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id WHERE prescriptions.drug = 'ferrous sulfate') AS t1 JOIN (SELECT admissions.subject_id, prescriptions.drug, prescriptions.startdate FROM prescriptions JOIN admissions ON prescriptions.hadm_id = admissions.hadm_id) AS t2 ON t1.subject_id = t2.subject_id WHERE DATETIME(t1.startdate) = DATETIME(t2.startdate) GROUP BY t2.drug) AS t3 WHERE t3.c1 <= 3
|
### Instruction:
count the number of patients for whom prednisone 50 mg po tabs was prescribed in the same hospital visit after having been diagnosed with pneumonia.
### Response:
|
SELECT COUNT(DISTINCT t1.uniquepid) FROM (SELECT patient.uniquepid, diagnosis.diagnosistime, patient.patienthealthsystemstayid FROM diagnosis JOIN patient ON diagnosis.patientunitstayid = patient.patientunitstayid WHERE diagnosis.diagnosisname = 'pneumonia') AS t1 JOIN (SELECT patient.uniquepid, medication.drugstarttime, patient.patienthealthsystemstayid FROM medication JOIN patient ON medication.patientunitstayid = patient.patientunitstayid WHERE medication.drugname = 'prednisone 50 mg po tabs') AS t2 WHERE t1.diagnosistime < t2.drugstarttime AND t1.patienthealthsystemstayid = t2.patienthealthsystemstayid
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.