question_id
int64
0
499
db_id
stringclasses
11 values
question
stringlengths
54
1.57k
evidence
stringlengths
0
418
SQL
stringlengths
41
2.22k
difficulty
stringclasses
3 values
100
card_games
I'm cataloguing European releases of Counterspell. How many of its printings were released with both a French and an Italian localization? I just need the count as a single number.
A printing is one release of the card identified by its set and its card number in that set; 'Counterspell' is the English card name as catalogued.
SELECT COUNT(DISTINCT c.id) FROM cards AS c JOIN foreign_data AS f ON c.uuid = f.uuid WHERE c.name = 'Counterspell' AND f.language IN ('French','Italian') AND c.id IN (SELECT c2.id FROM cards AS c2 JOIN foreign_data AS f2 ON c2.uuid = f2.uuid WHERE c2.name = 'Counterspell' AND f2.language = 'French' INTERSECT SELECT c3...
challenging
101
card_games
I'm putting together a localization report. Find the sets that belong to the same expansion type as "From the Vault: Lore" – include that set itself if it qualifies. Among those, which sets never received a name in any foreign language? For each one, give me the set's name and its release date. List each qualifying set...
Expansion type means the category a set belongs to, such as core, expansion or masters.
SELECT s.name, s.releaseDate FROM sets s WHERE s.type = (SELECT type FROM sets WHERE name = 'From the Vault: Lore') AND NOT EXISTS (SELECT 1 FROM set_translations t WHERE t.setCode = s.code AND t.translation IS NOT NULL) ORDER BY s.releaseDate
challenging
102
card_games
Which set contains the Aven Mindcensor printing that uses the newest card frame? I want the set's name and its release date. Count every printing, including promotional and online-only ones. If several printings share the newest frame, use the most recently released one; if the release dates tie too, list each such set...
Frame version: the frame style used for a printing; frame styles are identified by the year that style was introduced.
SELECT DISTINCT s.name AS setName, s.releaseDate FROM cards AS c JOIN sets AS s ON s.code = c.setCode WHERE c.name = 'Aven Mindcensor' AND CAST(c.frameVersion AS INTEGER) = (SELECT MAX(CAST(frameVersion AS INTEGER)) FROM cards WHERE name = 'Aven Mindcensor') AND s.releaseDate = (SELECT MAX(s2.releaseDate) FROM cards AS...
challenging
103
card_games
I'm auditing which recent products were never localized for Spanish-speaking markets. Can you find every set released in calendar year 2020 that has no Spanish name? For each of those, I just need the set code and the set's release date.
By "Spanish name" I mean the Spanish-language version of a set's name.
SELECT s.code, s.releaseDate FROM sets s WHERE s.releaseDate BETWEEN '2020-01-01' AND '2020-12-31' AND NOT EXISTS (SELECT 1 FROM set_translations t WHERE t.setCode = s.code AND t.language = 'Spanish' AND t.translation IS NOT NULL) ORDER BY s.releaseDate, s.code
challenging
104
card_games
I'm cataloguing special-release printings illustrated by Rob Alexander. What is the total converted mana cost across all cards illustrated by Rob Alexander whose original release falls in 2013? Please give me just that total as a single number. By 'released in 2013' I mean the calendar year from 1 January through 31 De...
Converted mana cost: the total numeric mana value of a card, e.g. a card costing {4}{W}{W} has a converted mana cost of 6.
SELECT SUM(convertedManaCost) AS total_converted_mana_cost FROM cards WHERE artist = 'Rob Alexander' AND substr(originalReleaseDate, 1, 4) = '2013'
challenging
105
card_games
We're planning translation work for upcoming set releases and want to know how extensively a recent release year was localized. What was the average number of languages in which sets released in 2016 had their names translated? By 'released in 2016' I mean the release date falls within calendar year 2016. Every set rel...
Set name translation: the set's name rendered in another language.
SELECT ROUND(AVG(n), 2) AS avg_languages FROM (SELECT s.id, COUNT(DISTINCT CASE WHEN st.translation IS NOT NULL AND TRIM(st.translation) <> '' THEN st.language END) AS n FROM sets s LEFT JOIN set_translations st ON s.code = st.setCode WHERE substr(s.releaseDate, 1, 4) = '2016' GROUP BY s.id)
challenging
106
card_games
For the blocks named exactly "Masques" and "Mirage", how widely were their sets localized? For each of these two blocks, give me one row with the block's name, how many of its sets have an official translated name, and the total number of cards in the base sets of those sets combined. Base set size means the number of ...
SELECT s.block AS block, COUNT(DISTINCT s.code) AS translated_sets, SUM(s.baseSetSize) AS total_base_set_size FROM sets s JOIN (SELECT DISTINCT setCode FROM set_translations) st ON s.code = st.setCode WHERE s.block IN ('Masques', 'Mirage') GROUP BY s.block ORDER BY s.block
challenging
107
card_games
I'm assembling a Japanese-language boros deck and want to check which cards need careful rules review. For every card that has a boros watermark and a Japanese printing, please give me: the Japanese card name, the English card type, and the total number of official rulings recorded for that card. A card is identified b...
Boros watermark means the watermark is marked 'boros' on the card; a Japanese printing is the foreign data entry in Japanese; rulings are the official rules clarifications recorded for a card.
SELECT f.name AS japanese_card_name, c.type AS card_type, SUM((SELECT COUNT(*) FROM rulings r WHERE r.uuid = c.uuid)) AS ruling_count FROM cards c JOIN foreign_data f ON c.uuid = f.uuid WHERE c.watermark = 'boros' AND f.language = 'Japanese' GROUP BY f.name, c.type ORDER BY f.name, c.type
challenging
108
card_games
I'm putting together a localization coverage report. Among the languages into which the card sets themselves were translated (i.e., have a set translation), which language has the fewest printings whose flavor text was translated into that language? Please give me the language name and the number of such printings. If ...
Set translation: a card set's official release in another language.
WITH set_langs AS ( SELECT DISTINCT language FROM set_translations ), counts AS ( SELECT fd.language, COUNT(*) AS printings FROM foreign_data fd WHERE fd.language IN (SELECT language FROM set_langs) AND fd.flavorText IS NOT NULL AND fd.flavorText <> '' GROUP BY fd.language ) SELECT l...
challenging
109
card_games
I'm building a French-language cube and want some big finishers for it. How many different creature cards with power 10 or greater have at least one printing in a set whose name has a French translation? Please return just that single number. Note: a set qualifies based on its name having a French translation, no matte...
French translation: the set's name as given in French.
SELECT COUNT(DISTINCT name) AS total_creature_cards FROM cards WHERE CAST(power AS REAL) >= 10 AND types LIKE '%Creature%' AND setCode IN (SELECT setCode FROM set_translations WHERE language = 'French' AND translation IS NOT NULL)
challenging
110
card_games
I'm researching the Commander banned list. Can you tell me the average mana value of the creature cards that are banned in at least one play format, considering only cards ranked in EDHRec's top 1000 most popular (ranks 1 through 1000, where rank 1 is the most popular)? Give me the average as a single number rounded to...
EDHRec rank: a card's popularity rank on EDHRec, from 1 (most popular) to 1000.
SELECT ROUND(AVG(t.cmc), 1) AS average_mana_value FROM (SELECT c.name, c.convertedManaCost AS cmc FROM cards AS c INNER JOIN legalities AS l ON l.uuid = c.uuid WHERE INSTR(c.types, 'Creature') > 0 AND c.edhrecRank BETWEEN 1 AND 1000 AND l.status = 'Banned' GROUP BY c.name, c.convertedManaCost) AS t
challenging
111
card_games
For a stats segment on creature power creep, I want to size the middle-to-big power band: how many card printings have a power greater than 3 and at most 10? Note that 3 itself is out (strictly greater than 3), but 10 itself counts (at most 10). Just the total number of printings, please.
A printing is one printed appearance of a card in a set – the same card name appearing in different sets counts as several printings.
SELECT COUNT(*) FROM cards WHERE CAST(power AS REAL) > 3 AND CAST(power AS REAL) <= 10
challenging
112
card_games
I want a single number: how many card printings originally released in 2014 belong to a set that carries a Magic: The Gathering Online code. A set counts as MTGO-available only if its MTGO code is present for that set. By 2014 I mean the calendar year 2014 of the printing's original release date. Count each printing se...
Magic: The Gathering Online (MTGO) is the official digital edition of the game; a set's MTGO code identifies that set within MTGO.
SELECT COUNT(*) AS printings FROM cards AS c JOIN sets AS s ON s.code = c.setCode WHERE substr(c.originalReleaseDate, 1, 4) = '2014' AND s.mtgoCode IS NOT NULL
challenging
113
card_games
I'm looking at Magic: The Gathering's localization coverage. Which foreign printing language has the fewest card printings overall, and how many printings does it have? Please count only languages in which Magic sets were officially printed—exclude one-off promotional gimmick languages. If several languages tie for the...
A printing language is a language in which Magic: The Gathering sets were officially released.
WITH counts AS (SELECT f.language, COUNT(*) AS printings FROM foreign_data AS f WHERE f.language IN (SELECT DISTINCT language FROM set_translations) GROUP BY f.language) SELECT language, printings FROM counts WHERE printings = (SELECT MIN(printings) FROM counts)
challenging
114
card_games
I'm auditing how thoroughly the Coldsnap expansion was localized into Italian. How many printings in the Coldsnap set have Italian rules text? I just need that single count.
By 'printing' I mean an individual card entry of a set, and by 'Italian rules text' I mean the Italian-language rules wording recorded for that printing. Coldsnap means the set named Coldsnap.
SELECT COUNT(DISTINCT c.uuid) AS printings_with_italian_rules_text FROM foreign_data AS f JOIN cards AS c ON c.uuid = f.uuid JOIN sets AS s ON s.code = c.setCode WHERE s.name = 'Coldsnap' AND f.language = 'Italian' AND TRIM(f.text) <> ''
challenging
115
card_games
Among the Commander-type expansion sets released in calendar year 2020 (1 January 2020 to 31 December 2020), I need the one with the highest total card count, so we can plan translation work. Please send me the set's id from the sets listing, its name, and the number of official languages it was released in. The total ...
Commander: a multiplayer expansion type of the game. Alchemy modifications: online-only variant versions of cards.
WITH cohort AS (SELECT * FROM sets WHERE type = 'commander' AND releaseDate >= '2020-01-01' AND releaseDate <= '2020-12-31') SELECT c.id, c.name, COUNT(DISTINCT st.language) AS languages FROM cohort c LEFT JOIN set_translations st ON st.setCode = c.code WHERE c.totalSetSize = (SELECT MAX(totalSetSize) FROM cohort) GROU...
challenging
116
card_games
I'm researching Magic: The Gathering's basic land card Swamp. How many foreign languages has it been printed in over its entire history? Count all printings across every set and year.
Swamp is the name of a Magic: The Gathering card.
SELECT COUNT(DISTINCT fd.language) AS language_count FROM foreign_data fd JOIN cards c ON fd.uuid = c.uuid WHERE c.name = 'Swamp'
challenging
117
card_games
I'm putting together a black artifact flavor-showcase section for a trade binder. How many mono-black Artifact cards have a foreign-language printing that shows flavor text in that language? By mono-black I mean black is the card's only colour, and by Artifact cards I include artifacts combined with another card type, ...
In Magic colour notation, B denotes black, and a card is mono-black when black is its only colour.
SELECT COUNT(DISTINCT c.name) AS card_count FROM cards AS c WHERE c.colors = 'B' AND c.type LIKE '%Artifact%' AND EXISTS (SELECT 1 FROM foreign_data AS f WHERE f.uuid = c.uuid AND LENGTH(f.flavorText) > 0)
challenging
118
codebase_community
What is the display name of the user who last edited the post "Examples for teaching: Correlation does not mean causation"?
SELECT T2.DisplayName FROM posts AS T1 INNER JOIN users AS T2 ON T1.LastEditorUserId = T2.Id WHERE T1.Title = 'Examples for teaching: Correlation does not mean causation'
moderate
119
codebase_community
Which users made exactly one history entry on at least one post with at least 1,000 views? Return their distinct user IDs.
WITH once_per_post AS (SELECT h.PostId, h.UserId FROM postHistory AS h JOIN posts AS p ON p.Id = h.PostId WHERE p.ViewCount >= 1000 AND h.UserId IS NOT NULL GROUP BY h.PostId, h.UserId HAVING COUNT(*) = 1) SELECT DISTINCT UserId FROM once_per_post ORDER BY UserId
moderate
120
codebase_community
What is the difference in percentage points between the 2010 and 2011 shares of all Student badges, taking the 2010 share minus the 2011 share?
SELECT CAST(SUM(IIF(STRFTIME('%Y', Date) = '2010', 1, 0)) AS REAL) * 100 / COUNT(Id) - CAST(SUM(IIF(STRFTIME('%Y', Date) = '2011', 1, 0)) AS REAL) * 100 / COUNT(Id) FROM badges WHERE Name = 'Student'
challenging
121
codebase_community
What percentage of posts authored by Community use the R-language tag? Round to two decimals.
SELECT ROUND(100.0 * SUM(CASE WHEN p.Tags LIKE '%<r>%' THEN 1 ELSE 0 END) / NULLIF(COUNT(*), 0), 2) FROM posts AS p JOIN users AS u ON u.Id = p.OwnerUserId WHERE u.DisplayName = 'Community'
challenging
122
codebase_community
Which post created in 2010 had the most favorites? Return its post ID and its owner's display name.
SELECT p.Id, u.DisplayName FROM posts AS p JOIN users AS u ON p.OwnerUserId = u.Id WHERE SUBSTR(p.CreaionDate, 1, 4) = '2010' AND p.FavoriteCount IS NOT NULL ORDER BY p.FavoriteCount DESC, p.Id ASC LIMIT 1
moderate
123
codebase_community
Give the view count of the post titled 'Computer game datasets' and the display name of its last editor.
SELECT DISTINCT p.ViewCount, u.DisplayName FROM posts AS p JOIN users AS u ON u.Id = p.LastEditorUserId WHERE LOWER(p.Title) = LOWER('Computer game datasets')
moderate
124
codebase_community
Give the text and author's display name for the latest ten comments on the post titled 'Analysing wind data with R', newest comment first.
SELECT c.Text, u.DisplayName FROM comments AS c JOIN posts AS p ON c.PostId = p.Id LEFT JOIN users AS u ON c.UserId = u.Id WHERE p.Title = 'Analysing wind data with R' ORDER BY c.CreationDate DESC, c.Id DESC LIMIT 10
moderate
125
codebase_community
Among all posts by the user with the highest reputation, what percentage have a score above 50? Round to two decimal places.
SELECT ROUND(100.0 * SUM(CASE WHEN Score > 50 THEN 1 ELSE 0 END) / NULLIF(COUNT(*), 0), 2) FROM posts WHERE OwnerUserId IN ( SELECT Id FROM users WHERE Reputation = (SELECT MAX(Reputation) FROM users) )
challenging
126
codebase_community
Among comments attached to existing posts with exactly one comment record in the data, how many have a score of zero?
SELECT COUNT(*) FROM comments AS c JOIN posts AS p ON p.Id = c.PostId WHERE c.Score = 0 AND c.PostId IN (SELECT x.PostId FROM comments AS x GROUP BY x.PostId HAVING COUNT(*) = 1)
simple
127
codebase_community
I'd like to gauge the standing of our United Kingdom contributor community on the site. Can you give me the combined reputation of the users based in the United Kingdom who have posted on the site, as a single total? Please write the country by its full name, "United Kingdom", and don't substitute abbreviations. I just...
Reputation is the score the site assigns each user. A user who has posted owns at least one item in the site's post collection.
SELECT SUM(u.Reputation) AS combined_reputation FROM users u WHERE u.Location LIKE '%United Kingdom%' AND u.Id IN (SELECT p.OwnerUserId FROM posts p WHERE p.OwnerUserId IS NOT NULL)
challenging
128
codebase_community
I want to profile the users who drop links in comment threads. What is the average age of the users who posted a comment containing a website link? Please round it to two decimal places. That single value is all I need back.
A comment counts as containing a website if its content contains 'http://'.
SELECT ROUND(AVG(T.Age), 2) AS average_age FROM (SELECT DISTINCT T2.Id, T2.Age FROM comments AS T1 INNER JOIN users AS T2 ON T1.UserId = T2.Id WHERE T1.Text LIKE '%http://%') AS T
challenging
129
codebase_community
I'm profiling how seasoned our Organizer badge holders in Germany are. Among the users who earned the Organizer badge and are based in Germany, how many had already earned 5 badges before they got the Organizer badge? Just the count, please. Note: "before" means strictly earlier - badges earned at the same moment as th...
Organizer badge: the badge whose name is Organizer.
WITH organizer AS (SELECT UserId, MIN(Date) AS organizer_date FROM badges WHERE Name = 'Organizer' GROUP BY UserId) SELECT COUNT(*) AS user_count FROM organizer o JOIN users u ON u.Id = o.UserId WHERE u.Location LIKE '%Germany%' AND (SELECT COUNT(*) FROM badges b WHERE b.UserId = o.UserId AND b.Date < o.organizer_date)...
challenging
130
codebase_community
I'm putting together a report for the site owners on where people who started posting during 2010 were located, with a focus on India. Could you tell me how many of the users whose first post was created in 2010 are located in India? By 2010 I mean the calendar year 2010, and by India I mean the country itself, not any...
A user's first post is the earliest-created post among the posts that user owns.
WITH RECURSIVE fp AS (SELECT OwnerUserId AS uid, MIN(CreaionDate) AS fdate FROM posts WHERE OwnerUserId IS NOT NULL GROUP BY OwnerUserId), locs AS (SELECT u.Id AS uid, u.Location AS loc FROM users u JOIN fp ON fp.uid = u.Id WHERE fp.fdate >= '2010-01-01' AND fp.fdate < '2011-01-01'), parts(uid, head, tail) AS (SELECT u...
challenging
131
codebase_community
I'm profiling the authors behind poorly received R posts to see if they tend to be low-reputation members. Can you give me the average reputation of the users who own posts tagged with the R tag that have a score below 20? Just the single number, rounded to the nearest whole number.
'r' is the tag used on this site for the R programming language for statistical computing.
SELECT ROUND(AVG(u.Reputation)) AS avg_reputation FROM users u WHERE u.Id IN (SELECT p.OwnerUserId FROM posts p WHERE p.Score < 20 AND p.Tags LIKE '%' || '<' || 'r' || '>' || '%')
challenging
132
codebase_community
I'm putting together the yearly activity report with a Germany-focused breakdown of who did the editing, covering posts created in calendar year 2012. For the 2012 posts whose last editor is a user based in Germany, I need the total score; and for all other posts created in 2012, I need their total score as well. Also,...
A post's last editor is the user who made its most recent edit.
WITH posts_2012 AS (SELECT Id, Score, LastEditorUserId AS EditorId FROM posts WHERE CreaionDate >= '2012-01-01' AND CreaionDate < '2013-01-01'), german_editors AS (SELECT DISTINCT u.Id, u.Reputation FROM posts_2012 p JOIN users u ON u.Id = p.EditorId WHERE u.Location LIKE '%Germany%') SELECT (SELECT SUM(p.Score) FROM p...
challenging
133
codebase_community
I'm reviewing R-language activity on the site. I'd like to gauge the standing of the community members behind the highly-rated R posts: what is the combined reputation of the users who own a post with a score of exactly 10 that carries the R programming language tag? Please return just that single number. Note that by ...
SELECT SUM(u.Reputation) AS combined_reputation FROM users u WHERE u.Id IN (SELECT p.OwnerUserId FROM posts p WHERE p.Score = 10 AND p.Tags LIKE '%' || '<' || 'R' || '>' || '%')
challenging
134
codebase_community
I'd like to gauge the standing of the community members behind the R posts on one day. Could you tell me the combined reputation of the users who own the posts tagged R that were last active on 2014-08-27? I just need that one number, covering the whole calendar day 2014-08-27.
R: the R language for statistical computing.
SELECT SUM(Reputation) AS combined_reputation FROM users WHERE Id IN (SELECT OwnerUserId FROM posts WHERE Tags LIKE '%' || '<' || 'R' || '>' || '%' AND LasActivityDate LIKE '2014-08-27%')
challenging
135
codebase_community
What is the total score of the questions tagged 'r' that link to the question titled "A Probability distribution value exceeding 1 is OK?"? I only need the total score of those linking questions.
'r' here means the R programming language for statistical computing, not the letter on its own.
WITH target AS (SELECT Id FROM posts WHERE Title = 'A Probability distribution value exceeding 1 is OK?'), linkers AS (SELECT DISTINCT pl.PostId AS pid FROM postLinks pl INNER JOIN target tg ON pl.RelatedPostId = tg.Id) SELECT SUM(p.Score) AS total_score FROM linkers l INNER JOIN posts p ON p.Id = l.pid WHERE EXISTS (S...
challenging
136
codebase_community
I'm profiling users by where they say they live. Among the users located in Germany, who has the second most badges of all time? By second most I mean the highest badge total strictly below the top holder's total. If several users tie at that total, include all of them. Please give me each such user's display name and ...
Badges: the badges a user has obtained, one badge award per record.
WITH per_user AS (SELECT u.Id, u.DisplayName, COUNT(b.Id) AS badge_count FROM users u LEFT JOIN badges b ON b.UserId = u.Id WHERE u.Location LIKE '%Germany%' GROUP BY u.Id, u.DisplayName) SELECT DisplayName, badge_count FROM per_user WHERE badge_count = (SELECT MAX(badge_count) FROM per_user p2 WHERE p2.badge_count < (...
challenging
137
codebase_community
I'm planning regional outreach and want to know which California-based account draws the most profile attention. Among users whose stated location shows they are based in California, give me the user id, display name, profile view count, and reputation of the user or users with the most profile views. If several such u...
CA is the two-letter state code for California.
WITH ca AS (SELECT Id, DisplayName, Views, Reputation FROM users WHERE INSTR(',' || REPLACE(UPPER(TRIM(Location)), ' ', '') || ',', ',' || 'CA' || ',') > 0 OR INSTR(',' || REPLACE(UPPER(TRIM(Location)), ' ', '') || ',', ',' || UPPER('California') || ',') > 0) SELECT Id, DisplayName, Views, Reputation FROM ca WHERE View...
challenging
138
codebase_community
We're profiling our most respected members by where they live, focusing on York, England (the English city itself; a location listed as just "York" counts). Who is the most influential user based there – the one with the highest reputation – and what is their age? If several users tie for the highest reputation, give m...
SELECT Age FROM users WHERE instr(',' || Location || ',', ',' || 'York' || ',') > 0 AND Reputation = (SELECT MAX(Reputation) FROM users WHERE instr(',' || Location || ',', ',' || 'York' || ',') > 0)
challenging
139
codebase_community
I'm preparing a report on international participation. How many users located in India had earned a Yearling badge before 2014? 'Before 2014' should mean before 1 January 2014. I just need the single count, nothing else.
'Yearling' is a badge a member earns for a year of activity on the site.
SELECT COUNT(DISTINCT T1.UserId) AS user_count FROM badges AS T1 INNER JOIN users AS T2 ON T1.UserId = T2.Id WHERE T2.Location LIKE '%India%' AND T1.Name = 'Yearling' AND T1.Date < '2014-01-01'
challenging
140
codebase_community
I'm putting together a summary of how active badge-holders present themselves on the site. How many different display names appear among the adult users who obtained the Supporter badge? By adult I mean age 19 to 65 inclusive, and please cover all time. I just need that one number.
NaN stands for a user who never set a display name.
SELECT COUNT(DISTINCT CASE WHEN u.DisplayName IS NULL OR u.DisplayName = 'NaN' THEN NULL ELSE u.DisplayName END) AS different_display_names FROM users AS u INNER JOIN badges AS b ON u.Id = b.UserId WHERE b.Name = 'Supporter' AND u.Age BETWEEN 19 AND 65
challenging
141
codebase_community
Among all posts whose title contains the phrase 'principal component scores', which one has the most related posts linked to it? For each such post, give me the post title and the number of related posts. If several posts tie for the most, list every one of them with their counts. The count should cover related posts a...
A related post is another post that the community's link records connect to a given post.
WITH counts AS (SELECT p.Id AS post_id, p.Title AS title, COUNT(DISTINCT pl.RelatedPostId) AS related_posts FROM posts p JOIN postLinks pl ON pl.PostId = p.Id WHERE p.Title LIKE '%principal component scores%' GROUP BY p.Id, p.Title) SELECT title, related_posts FROM counts WHERE related_posts = (SELECT MAX(related_posts...
challenging
142
codebase_community
I'm auditing accounts on the stats forum. What is the id of the youngest user account whose display name is Michael? If two or more such accounts tie as the youngest, give me the smallest id.
SELECT Id FROM users WHERE DisplayName = 'Michael' AND Age = (SELECT MIN(Age) FROM users WHERE DisplayName = 'Michael') ORDER BY Id LIMIT 1
challenging
143
codebase_community
I'm trying to gauge how many users the bounty feature drew back when it first ran. How many users offered a bounty of 30 or more on some post between 1 January 2010 (inclusive) and 1 January 2011 (exclusive), going by the date the bounty was recorded? By the user who offered a bounty, I mean the post's owner - the owne...
A bounty is a reputation reward a user attaches to a post, recorded as an amount.
SELECT COUNT(DISTINCT COALESCE(CAST(p.OwnerUserId AS TEXT), p.OwnerDisplayName)) AS users FROM votes v JOIN posts p ON v.PostId = p.Id WHERE v.BountyAmount >= 30 AND v.CreationDate >= '2010-01-01' AND v.CreationDate < '2011-01-01'
challenging
144
codebase_community
What was the average reputation of users located in India who created a post in 2010? Please give me a single number rounded to two decimal places. Note: 'in 2010' means the calendar year 2010 based on the post's creation date, and any type of post counts. A user counts as located in India only if their location is act...
SELECT ROUND(AVG(u.Reputation), 2) AS avg_reputation FROM users u WHERE (trim(u.Location) = 'India' OR (instr(u.Location, ',') > 0 AND trim(substr(u.Location, instr(u.Location, ',') + 1)) = 'India')) AND u.Id IN (SELECT p.OwnerUserId FROM posts p WHERE p.CreaionDate >= '2010-01-01' AND p.CreaionDate < '2011-01-01')
challenging
145
codebase_community
I'm profiling our most active contributors of 2012. Among the users who created more than ten posts in 2012 (judged by each post's creation date), what is their average number of up-votes cast and their average age? Please give me a single row with both averages, each rounded to two decimal places.
Up-vote: a vote a user cast in favor of a post.
WITH active AS (SELECT OwnerUserId FROM posts WHERE CreaionDate >= '2012-01-01' AND CreaionDate < '2013-01-01' GROUP BY OwnerUserId HAVING COUNT(*) > 10) SELECT ROUND(AVG(u.UpVotes), 2) AS avg_upvotes, ROUND(AVG(u.Age), 2) AS avg_age FROM active AS a JOIN users AS u ON u.Id = a.OwnerUserId
challenging
146
codebase_community
For each month of 2010, how many posts that have no more than two answers received a link during that month? A month with none counts as zero. Give me the average across all twelve months of 2010, rounded to two decimals.
A link is a recorded connection that associates one post with another post of the site.
SELECT ROUND(CAST(SUM(month_cnt) AS REAL) / 12, 2) AS average FROM (SELECT STRFTIME('%m', T1.CreationDate) AS mon, COUNT(DISTINCT T1.PostId) AS month_cnt FROM postLinks AS T1 INNER JOIN posts AS T2 ON T1.PostId = T2.Id WHERE T2.AnswerCount <= 2 AND STRFTIME('%Y', T1.CreationDate) = '2010' GROUP BY mon)
challenging
147
codebase_community
I'm reviewing our 2010 content. What percentage of posts created in 2010 that have a score above 5 were NOT made by high-reputation users? By high-reputation I mean a user with a reputation of at least 1000. Please give me just the single percentage value, rounded to two decimal places. Use the post's creation date to ...
high-reputation: reputation of at least 1000
SELECT ROUND(CAST(SUM(IIF(T2.Reputation >= 1000, 0, 1)) AS REAL) * 100 / COUNT(T1.Id), 2) AS percentage FROM posts AS T1 LEFT JOIN users AS T2 ON T1.OwnerUserId = T2.Id WHERE T1.Score > 5 AND strftime('%Y', T1.CreaionDate) = '2010'
challenging
148
codebase_community
I'm reviewing the history of the question 'Why square the difference instead of taking the absolute value in standard deviation?'. For that post, who left the most edit comments, and how many did they leave? Please give me each editor's display name along with their number of edit comments on that post. If several edit...
An edit comment is the note an editor records together with a revision of a post, not a comment posted under the post.
WITH target AS (SELECT Id FROM posts WHERE Title = 'Why square the difference instead of taking the absolute value in standard deviation?'), counts AS (SELECT u.DisplayName, COUNT(*) AS n FROM postHistory h JOIN users u ON u.Id = h.UserId WHERE h.PostId IN (SELECT Id FROM target) AND h.Comment IS NOT NULL AND TRIM(h.Co...
challenging
149
debit_card_specializing
For each of the SME, LAM, and KAM segments, identify the CZK customer with the lowest total recorded consumption in 2013, breaking a tie by smaller customer ID. What are the differences between those customers' 2013 totals in SME minus LAM, LAM minus KAM, and KAM minus SME order? Round each to two decimals.
WITH annual AS ( SELECT c.Segment, c.CustomerID, SUM(y.Consumption) AS total FROM customers AS c JOIN yearmonth AS y ON y.CustomerID = c.CustomerID WHERE c.Currency = 'CZK' AND y.Date BETWEEN '201301' AND '201312' AND y.Consumption IS NOT NULL AND c.Segment IN ('SME', 'LAM', 'KAM') GROUP BY c.Segment, c.CustomerID ), r...
challenging
150
debit_card_specializing
Among EUR-paying customers in the SME, LAM, and KAM segments, which segments had the highest and lowest percentage increase in total consumption from 2012 to 2013? Return each extreme segment and its increase percentage, rounded to two decimal places; include ties.
WITH annual AS ( SELECT c.Segment, SUM(CASE WHEN SUBSTR(y.Date, 1, 4) = '2012' THEN y.Consumption ELSE 0 END) AS total_2012, SUM(CASE WHEN SUBSTR(y.Date, 1, 4) = '2013' THEN y.Consumption ELSE 0 END) AS total_2013 FROM customers AS c JOIN yearmonth AS y ON c.CustomerID = y.CustomerID WHERE c.Currency = 'EUR' AND c.Segm...
challenging
151
debit_card_specializing
For the customer who paid 634.8 on 2012-08-25, what is the relative change in annual consumption from 2012 to 2013, calculated as (2013 total - 2012 total) / 2012 total and rounded to four decimal places?
SELECT ROUND(CAST(1.0 * ( SUM(CASE WHEN SUBSTR(ym.Date, 1, 4) = '2013' THEN ym.Consumption ELSE 0 END) - SUM(CASE WHEN SUBSTR(ym.Date, 1, 4) = '2012' THEN ym.Consumption ELSE 0 END) ) / NULLIF(SUM(CASE WHEN SUBSTR(ym.Date, 1, 4) = '2012' THEN ym.Consumption ELSE 0 END), 0) AS DECIMAL(20, 8)), 4) FROM yearmonth AS ym WH...
challenging
152
debit_card_specializing
How many customers who pay in EUR and had gas consumption in 2012 also had gas consumption in 2013? I just need a single number: the count of such customers. By 2012 and 2013 I mean those calendar years, and gas consumption in any month of the year counts.
SELECT COUNT(*) AS customers FROM (SELECT CustomerID FROM yearmonth WHERE SUBSTR(Date,1,4) = '2012' AND CustomerID IN (SELECT CustomerID FROM customers WHERE Currency = 'EUR') INTERSECT SELECT CustomerID FROM yearmonth WHERE SUBSTR(Date,1,4) = '2013')
challenging
153
debit_card_specializing
I'm reviewing our 2012 performance and want to see which client segments hold our small-scale customers. For each client segment, can you tell me how many customers had total consumption below 30,000 over the whole of 2012? Please count only customers who used their cards at some point during 2012, and treat 30,000 as ...
Consumption means the amount spent through a customer's fuel cards.
WITH yearly AS (SELECT CustomerID, SUM(Consumption) AS total_consumption FROM yearmonth WHERE Date >= '201201' AND Date <= '201212' GROUP BY CustomerID HAVING SUM(Consumption) < 30000) SELECT c.Segment AS segment, COUNT(*) AS customers FROM yearly AS y INNER JOIN customers AS c ON c.CustomerID = y.CustomerID GROUP BY c...
challenging
154
debit_card_specializing
I'm reviewing 2013 uptake and want to know the genuinely active cardholder base in each client segment. For each client segment, how many of that segment's customers consumed any fuel at all during the calendar year 2013? I just need the client segment and the number of customers who consumed fuel in 2013, nothing else...
A customer's consumption for a month is the amount of fuel recorded against them for that month; by 'consumed any fuel in 2013' I mean they had fuel recorded against them in at least one month of 2013.
SELECT c.Segment AS segment, COUNT(DISTINCT y.CustomerID) AS customers_with_fuel_2013 FROM customers AS c INNER JOIN yearmonth AS y ON c.CustomerID = y.CustomerID WHERE y.Date BETWEEN '201301' AND '201312' AND y.Consumption > 0 GROUP BY c.Segment ORDER BY c.Segment
challenging
155
debit_card_specializing
I want to gauge how spread out our high-value fuelling activity in the Czech Republic was over the recorded window. How many whole minutes elapsed from the first to the last fuel transaction at gas stations in the Czech Republic with a price over 1000? Please round down to whole minutes.
Czech Republic means the gas station is in the CZE country.
SELECT (strftime('%s', MAX(Date || ' ' || Time)) - strftime('%s', MIN(Date || ' ' || Time))) / (5 * 13 - 5) AS minutes FROM transactions_1k AS T1 INNER JOIN gasstations AS T2 ON T1.GasStationID = T2.GasStationID WHERE T2.Country = 'CZE' AND T1.Price > 1000
challenging
156
debit_card_specializing
I'm preparing a loyalty review of our steadily active customers in 2013. For each currency, I'd like to know how many customers bought fuel in every month from January through November 2013, with both January and November included. Please give me the currency and that customer count. If several currencies tie, list the...
Consumption means the total fuel a customer purchased in a month on their fuel card; a customer counts for a month if they had any consumption that month.
WITH RECURSIVE months(m) AS (SELECT '201301' UNION ALL SELECT CAST(CAST(m AS INTEGER) + 1 AS TEXT) FROM months WHERE m < '201311'), steady AS (SELECT CustomerID FROM yearmonth WHERE Date BETWEEN '201301' AND '201311' AND Consumption > 0 GROUP BY CustomerID HAVING COUNT(DISTINCT Date) = (SELECT COUNT(*) FROM months)) SE...
challenging
157
debit_card_specializing
I'm putting together currency-specific pricing proposals and need a sense of typical quarterly fuel consumption. Among customers who have fuel consumption recorded in the second quarter of 2013 (April, May and June 2013), what is the average amount of fuel consumed over the whole quarter by an EUR-paying customer, and ...
EUR-paying / CZK-paying: a customer whose account currency is EUR / CZK
WITH q2 AS (SELECT CustomerID, SUM(Consumption) AS total FROM yearmonth WHERE Date BETWEEN '201304' AND '201306' GROUP BY CustomerID) SELECT ROUND(AVG(CASE WHEN c.Currency = 'EUR' THEN q2.total END), 2) AS eur_avg_quarter, ROUND(AVG(CASE WHEN c.Currency = 'CZK' THEN q2.total END), 2) AS czk_avg_quarter FROM customers c...
challenging
158
debit_card_specializing
I want to see how much our busiest month grew from 2012 to 2013. What was the difference between our peak monthly total consumption in 2013 and our peak monthly total consumption in 2012, in consumption units, rounded to the nearest whole number? By total consumption in a calendar month I mean the consumption of the wh...
SELECT ROUND((SELECT SUM(Consumption) FROM yearmonth WHERE SUBSTR(Date, 1, 4) = '2013' GROUP BY SUBSTR(Date, 5, 2) ORDER BY SUM(Consumption) DESC LIMIT 1) - (SELECT SUM(Consumption) FROM yearmonth WHERE SUBSTR(Date, 1, 4) = '2012' GROUP BY SUBSTR(Date, 5, 2) ORDER BY SUM(Consumption) DESC LIMIT 1), 0) AS difference
challenging
159
debit_card_specializing
I'm reviewing customer 15621's fuel spending on the fleet card in 2013. What was their average fuel consumption per month, counting only the months in which they actually purchased fuel? Give me the single average value rounded to two decimal places.
SELECT ROUND(SUM(Consumption) / COUNT(*), 2) AS average_monthly_consumption FROM yearmonth WHERE CustomerID = 15621 AND Date BETWEEN '201301' AND '201312' AND Consumption > 0;
challenging
160
debit_card_specializing
I want to compare how much a typical Czech-koruna-billed client spent versus a euro-billed client during 2012, to see whether the two currency segments behave differently. Please give me the difference between the average 2012 consumption of a CZK-paying customer and the average 2012 consumption of an EUR-paying custom...
Consumption means the monthly consumption amount recorded per customer.
WITH per_customer AS (SELECT CustomerID, SUM(Consumption) AS tot_2012 FROM yearmonth WHERE SUBSTR(Date, 1, 4) = '2012' GROUP BY CustomerID) SELECT ROUND(AVG(CASE WHEN c.Currency = 'CZK' THEN p.tot_2012 END) - AVG(CASE WHEN c.Currency = 'EUR' THEN p.tot_2012 END), 0) AS diff FROM customers AS c JOIN per_customer AS p ON...
challenging
161
debit_card_specializing
I'm sizing a premium offer for our heaviest corporate fuel buyers ahead of renewals. How many KAM-segment customers paying in CZK had total fuel consumption above 1 million (1,000,000) in calendar year 2013? I just need that number of customers.
KAM is one of our client segments.
SELECT COUNT(*) AS customer_count FROM (SELECT T2.CustomerID FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Currency = 'CZK' AND T1.Segment = 'KAM' AND T2.Date LIKE '2013%' GROUP BY T2.CustomerID HAVING SUM(T2.Consumption) > 1000000)
challenging
162
debit_card_specializing
For my February 2013 activity report: how many SME customers actually purchased gas in February 2013? Please give me just a single whole number - the count of SME customers who consumed gas during the calendar month of February 2013 (Feb 1-28, 2013).
By "gas" I mean gasoline (motor fuel) purchases, not natural gas.
SELECT COUNT(DISTINCT T2.CustomerID) AS sme_gas_customers FROM customers AS T1 INNER JOIN yearmonth AS T2 ON T1.CustomerID = T2.CustomerID WHERE T1.Segment = 'SME' AND T2.Date = '201302' AND T2.Consumption > 0
challenging
163
european_football_2
Which away teams are tied for the most away wins in the Scottish Premier League 2009/2010 season?
WITH wins AS ( SELECT m.away_team_api_id, COUNT(*) AS n FROM Match AS m JOIN League AS l ON l.id = m.league_id WHERE l.name = 'Scotland Premier League' AND m.season = '2009/2010' AND m.away_team_goal > m.home_team_goal GROUP BY m.away_team_api_id ) SELECT t.team_long_name FROM wins AS w JOIN Team AS t ON t.team_api_id ...
challenging
164
european_football_2
List the long name of teams with above-average build-up play passing in 2012.
SELECT DISTINCT t4.team_long_name FROM Team_Attributes AS t3 INNER JOIN Team AS t4 ON t3.team_api_id = t4.team_api_id WHERE SUBSTR(t3.`date`, 1, 4) = '2012' AND t3.buildUpPlayPassing > ( SELECT CAST(SUM(t2.buildUpPlayPassing) AS REAL) / COUNT(t1.id) FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t...
challenging
165
european_football_2
List the ten players taller than 180 cm with the highest mean recorded heading accuracy, highest first. Break mean ties by player API ID.
SELECT p.player_name FROM Player AS p JOIN Player_Attributes AS a ON a.player_api_id = p.player_api_id WHERE p.height > 180 GROUP BY p.player_api_id, p.player_name ORDER BY AVG(a.heading_accuracy) DESC, p.player_api_id LIMIT 10
moderate
166
european_football_2
List the name of leagues in which the average goals by the home team is higher than the away team in the 2009/2010 season.
SELECT t1.name FROM League AS t1 INNER JOIN Match AS t2 ON t1.id = t2.league_id WHERE t2.season = '2009/2010' GROUP BY t1.name HAVING (CAST(SUM(t2.home_team_goal) AS REAL) / COUNT(DISTINCT t2.id)) - (CAST(SUM(t2.away_team_goal) AS REAL) / COUNT(DISTINCT t2.id)) > 0
challenging
167
european_football_2
Between the tallest and shortest players, who has the higher average finishing attribute across his recorded assessments? Give the player's name.
SELECT p.player_name FROM Player AS p JOIN Player_Attributes AS a ON a.player_api_id = p.player_api_id WHERE p.height IN ((SELECT MAX(height) FROM Player), (SELECT MIN(height) FROM Player)) GROUP BY p.player_api_id, p.player_name ORDER BY AVG(a.finishing) DESC, p.player_api_id LIMIT 1
challenging
168
european_football_2
What is Abdou Diallo's mean recorded ball-control score minus Aaron Appindangoye's mean recorded ball-control score?
SELECT CAST(SUM(CASE WHEN t1.player_name = 'Abdou Diallo' THEN t2.ball_control ELSE 0 END) AS REAL) / COUNT(CASE WHEN t1.player_name = 'Abdou Diallo' THEN t2.id ELSE NULL END) - CAST(SUM(CASE WHEN t1.player_name = 'Aaron Appindangoye' THEN t2.ball_control ELSE 0 END) AS REAL) / COUNT(CASE WHEN t1.player_name = 'Aaron A...
challenging
169
european_football_2
By what percentage is Ariel Borysiuk's overall rating in his latest attribute record higher than Paulin Puel's latest overall rating? Round to two decimals.
WITH latest AS ( SELECT p.player_name, a.overall_rating, ROW_NUMBER() OVER (PARTITION BY p.player_api_id ORDER BY a.date DESC, a.id DESC) AS rn FROM Player AS p JOIN Player_Attributes AS a ON a.player_api_id = p.player_api_id WHERE p.player_name IN ('Ariel Borysiuk', 'Paulin Puel') ) SELECT ROUND(100.0 * (MAX(CASE WHEN...
challenging
170
european_football_2
On what date did Kevin Constant first record his highest crossing score?
SELECT pa.date FROM Player_Attributes AS pa JOIN Player AS p ON p.player_fifa_api_id = pa.player_fifa_api_id WHERE p.player_name = 'Kevin Constant' AND pa.crossing IS NOT NULL ORDER BY pa.crossing DESC, pa.date ASC LIMIT 1
moderate
171
european_football_2
Among players shorter than 180 cm, what percentage have at least one recorded overall rating above 70? Round to two decimal places.
SELECT ROUND(100.0 * COUNT(DISTINCT CASE WHEN a.overall_rating > 70 THEN p.player_api_id END) / NULLIF(COUNT(DISTINCT p.player_api_id), 0), 2) FROM Player AS p LEFT JOIN Player_Attributes AS a ON a.player_api_id = p.player_api_id WHERE p.height < 180
moderate
172
european_football_2
What is the average height, in centimetres, of the players taller than 180 cm who have appeared in the home team's number-3 lineup slot? This should cover the whole recorded match history with no season or date restriction. 'Taller than 180' means strictly taller than 180 cm. Please round the final average to two decim...
Number-3 lineup slot: each match records a home team's starting eleven as eleven ordered player slots; the number-3 slot is the home team's third slot.
SELECT ROUND(AVG(height), 2) AS avg_height FROM (SELECT p.height AS height FROM Player p JOIN Match m ON m.home_player_3 = p.player_api_id WHERE p.height > 180 GROUP BY p.player_api_id)
challenging
173
european_football_2
I'm sizing up how defensive-minded the young generation is. Among players born after 1990 (i.e., born in 1991 or later) who have a defensive work rate rating, what share are rated high? A player counts as rated high if they've been rated high at any point in their career. Give me that share as a percentage rounded to t...
Defensive work rate: a player's rating for defensive effort, on a low / medium / high scale.
SELECT ROUND(100.0 * (SELECT COUNT(DISTINCT pa.player_api_id) FROM Player p JOIN Player_Attributes pa ON pa.player_api_id = p.player_api_id WHERE CAST(STRFTIME('%Y', p.birthday) AS INTEGER) > 1990 AND pa.defensive_work_rate = 'high') / (SELECT COUNT(DISTINCT pa.player_api_id) FROM Player p JOIN Player_Attributes pa ON ...
challenging
174
european_football_2
I've shortlisted the players whose overall rating as of 31 December 2010 was above 80 - strictly above 80, that is. How many matches did these players play on average during the 2010/2011 season? Please give me just that single average, rounded to two decimals.
WITH latest AS (SELECT player_api_id, MAX(date) AS md FROM Player_Attributes WHERE date <= '2010-12-31 00:00:00' GROUP BY player_api_id), shortlist AS (SELECT p.player_api_id FROM latest l JOIN Player_Attributes a ON a.player_api_id = l.player_api_id AND a.date = l.md JOIN Player p ON p.player_api_id = l.player_api_id ...
challenging
175
european_football_2
What is the average height in centimeters of players whose current defensive work rate grade is not medium? Use each player's most recent rating record to determine their current grade, and round the result to two decimal places. I just need that single number.
Defensive work rate grades run low, medium and high.
WITH latest AS (SELECT player_api_id, defensive_work_rate, ROW_NUMBER() OVER (PARTITION BY player_api_id ORDER BY date DESC, id DESC) AS rn FROM Player_Attributes) SELECT ROUND(AVG(p.height), 2) AS average_height FROM latest l JOIN Player p ON p.player_api_id = l.player_api_id WHERE l.rn = 1 AND l.defensive_work_rate I...
challenging
176
european_football_2
I'm preparing a report on team playing styles. First, consider only teams whose chance creation passing class was Risky at any point in the recorded history. Among those, I want the short names that are carried by more than one club. For each such short name, please give me: the short name, the number of clubs that car...
A team's chance creation passing class is 'Risky' when chanceCreationPassingClass = 'Risky'; its chance creation passing risk is the chanceCreationPassing value in force on the date in question.
WITH risky AS (SELECT DISTINCT team_api_id FROM Team_Attributes WHERE chanceCreationPassingClass = 'Risky'), cur AS (SELECT team_api_id, chanceCreationPassing FROM Team_Attributes ta WHERE ta.date = (SELECT MAX(date) FROM Team_Attributes x WHERE x.team_api_id = ta.team_api_id AND x.date <= '2014-09-19 00:00:00')) SELEC...
challenging
177
european_football_2
I want to gauge how tall the current medium-defensive-work players from the 1990-1995 birth cohort are. Please find the average height, in centimetres, of players born from 1990 through 1995 inclusive whose defensive work rating is medium, and round the average to two decimals. A player's rating is the grade on their m...
The defensive work rating grades are low, medium and high.
WITH latest_grade AS (SELECT player_api_id, defensive_work_rate, ROW_NUMBER() OVER (PARTITION BY player_api_id ORDER BY date DESC, id DESC) AS rn FROM Player_Attributes WHERE defensive_work_rate IN ('low', 'medium', 'high')) SELECT ROUND(AVG(p.height), 2) AS average_height FROM Player p JOIN latest_grade g ON g.player_...
challenging
178
european_football_2
What is the average weight of all left-footed players? Round the average to one decimal place.
Left-footed means the player's preferred foot when attacking is the left one.
SELECT ROUND(AVG(weight), 1) AS average_weight FROM Player WHERE player_api_id IN (SELECT player_api_id FROM Player_Attributes WHERE preferred_foot = 'left')
challenging
179
european_football_2
I'm putting together a participation report for the 2015/2016 season. For every player whose name starts with Adam and who weighs more than 170, I need the number of matches he played during that season. Please return, one row per qualifying player, the player's name and his number of matches played in the 2015/2016 se...
Played a match means being named in that match's lineup, for either the home or the away team.
WITH apps AS (SELECT id AS mid, home_player_1 AS pid FROM Match WHERE season='2015/2016' UNION ALL SELECT id, home_player_2 FROM Match WHERE season='2015/2016' UNION ALL SELECT id, home_player_3 FROM Match WHERE season='2015/2016' UNION ALL SELECT id, home_player_4 FROM Match WHERE season='2015/2016' UNION ALL SELECT i...
challenging
180
european_football_2
What was the build-up play dribbling class for the team from England with short name POR on 10 September 2015? I just need that single class value for that team on that calendar day.
SELECT t2.buildUpPlayDribblingClass FROM Team AS t1 INNER JOIN Team_Attributes AS t2 ON t1.team_api_id = t2.team_api_id WHERE t1.team_short_name = 'POR' AND t1.team_api_id IN (SELECT m.home_team_api_id FROM `Match` AS m INNER JOIN Country AS c ON c.id = m.country_id WHERE c.name = 'England' UNION SELECT m.away_team_api...
challenging
181
european_football_2
I'm looking at whether a fast attacking build-up actually converts into big results. Which clubs, playing at home, have won a match by at least 3 goals while their build-up play speed was rated fast at the time? For each such club, give me the club name, short name, and how many of those home wins it has - one row per ...
A club wins by at least 3 goals when its goal count minus the opponent's goal count is 3 or more; 'fast' means the club's build-up play speed class at that time is Fast.
SELECT t.team_long_name AS club_name, t.team_short_name AS short_name, COUNT(*) AS home_wins FROM `Match` m JOIN Team t ON t.team_api_id = m.home_team_api_id WHERE m.home_team_goal - m.away_team_goal >= 3 AND (SELECT ta.buildUpPlaySpeedClass FROM Team_Attributes ta WHERE ta.team_api_id = m.home_team_api_id AND ta.date ...
challenging
182
european_football_2
I'm writing a piece about players who've suffered heavy away defeats. For each season, I'd like to know how many different players were in the away team's lineup for a match that the away side lost by five or more goals. Please give me one row per season that had at least one such match, showing the season label (like ...
WITH away_lineup AS (SELECT season, away_player_1 AS pid FROM Match WHERE home_team_goal - away_team_goal >= 5 UNION ALL SELECT season, away_player_2 FROM Match WHERE home_team_goal - away_team_goal >= 5 UNION ALL SELECT season, away_player_3 FROM Match WHERE home_team_goal - away_team_goal >= 5 UNION ALL SELECT season...
challenging
183
european_football_2
I want to find out which European league country had the largest group of exceptionally heavy players appear in its matches. For each country, I'm interested in players weighing 210 pounds or more who took part in matches played in that country's league - count players from both teams in each match. Please tell me whic...
WITH appearances AS (SELECT m.country_id, p.player_api_id FROM `Match` m JOIN Player p ON p.player_api_id IN (m.home_player_1, m.home_player_2, m.home_player_3, m.home_player_4, m.home_player_5, m.home_player_6, m.home_player_7, m.home_player_8, m.home_player_9, m.home_player_10, m.home_player_11, m.away_player_1, m.aw...
challenging
184
european_football_2
I'm studying squad physical profiles in Serie A. For the 2008/2009 season and the 2015/2016 season of the Italian league, I'd like to know how many players appeared in matches that season (i.e. were listed in a match's lineup, including players who appeared in both seasons), and the average height of those players in c...
A player appeared in a match if he is listed in that match's lineup (eleven home and eleven away players). Italian league = the league of the country Italy.
WITH italy AS ( SELECT * FROM `Match` WHERE country_id = (SELECT id FROM Country WHERE name = 'Italy') AND season IN ('2008/2009','2015/2016') ), slots AS ( SELECT id, season, home_player_1 AS pid FROM italy UNION ALL SELECT id, season, home_player_2 FROM italy UNION ALL SELECT id, season, home_player_3 FROM italy UNIO...
challenging
185
european_football_2
I'm putting together a report on current player abilities. How many players are over 180 cm tall and have a volley score above 70 on their most recent rating record? Judge each player by their current rating only, not their career history. For each player, use the rating record with the latest date; if a player has sev...
By volley I mean a player's ability to strike the ball while it is in the air, and a rating record is a dated assessment of a player's attributes.
WITH latest AS (SELECT player_api_id, volleys, ROW_NUMBER() OVER (PARTITION BY player_api_id ORDER BY date DESC, id DESC) AS rn FROM Player_Attributes) SELECT COUNT(DISTINCT t1.id) AS tall_volley_players FROM Player AS t1 INNER JOIN latest AS t2 ON t1.player_api_id = t2.player_api_id WHERE t1.height > 180 AND t2.rn = 1...
challenging
186
european_football_2
I'm reviewing home-match outcomes by lineup slot and want one number: across the whole player population, what is the average of the total home-team goals scored in the matches where a player appeared as the home team's third listed player? In other words, for each player, take all matches where they were the home team...
The home team's third listed player means the player recorded third in the home team's lineup for a match.
SELECT ROUND(SUM(m.home_team_goal) * 1.0 / COUNT(DISTINCT p.player_api_id), 2) AS avg_home_goals_per_player FROM Player AS p LEFT JOIN Match AS m ON m.home_player_3 = p.player_api_id
challenging
187
european_football_2
I'm studying where small, low-weight players are concentrated across European leagues. Which country's league matches featured the fewest players weighing at most 160 pounds? If several countries tie for the fewest, give me every tied country's name. Include all seasons in the database, and count the players who took p...
Players are associated with a country through the matches they played in that country's league; all 22 players of a match, the 11 of the home team and the 11 of the away team, took part in it.
WITH appearances AS (SELECT country_id, home_player_1 AS player_api_id FROM Match UNION SELECT country_id, home_player_2 FROM Match UNION SELECT country_id, home_player_3 FROM Match UNION SELECT country_id, home_player_4 FROM Match UNION SELECT country_id, home_player_5 FROM Match UNION SELECT country_id, home_player_6...
challenging
188
european_football_2
As of 1 January 2015, how many players preferred their left foot and had an attacking work rate below high (i.e. low or medium)? I just need the count of those players.
Attacking work rate is a rating on the scale low, medium, high; below high means low or medium. The player's preferred foot and work rate are the ones that held on 1 January 2015.
SELECT COUNT(DISTINCT pa.player_api_id) AS player_count FROM Player_Attributes AS pa JOIN (SELECT player_api_id, MAX(date) AS latest FROM Player_Attributes WHERE date <= '2015-01-01 00:00:00' GROUP BY player_api_id) AS t ON pa.player_api_id = t.player_api_id AND pa.date = t.latest WHERE pa.preferred_foot = 'left' AND p...
challenging
189
european_football_2
What percentage of left-footed players currently has a low attacking work rate? Use each player's most recent attribute record. Only count left-footed players whose current record includes an attacking work rate rating - those without one should be left out of the share. Give me a single percentage, rounded to one deci...
Attacking work rate: how much effort a player puts into attacking plays, rated low, medium or high.
WITH latest AS (SELECT player_api_id, MAX(date) AS d FROM Player_Attributes GROUP BY player_api_id) SELECT ROUND(100.0 * COUNT(DISTINCT CASE WHEN pa.attacking_work_rate = 'low' THEN pa.player_api_id END) / COUNT(DISTINCT CASE WHEN pa.attacking_work_rate IN ('low','medium','high') THEN pa.player_api_id END), 1) AS pct F...
challenging
190
european_football_2
I want to see which of the young Aaron-named players actually got playing time in 2015/2016. For every player born after 1990 whose name begins with 'Aaron', can you give me his name and the number of matches he played in during the 2015/2016 season (the season labelled 2015/2016)? A player counts as having played in a...
SELECT p.player_name, COUNT(DISTINCT m.match_id) AS matches FROM Player p LEFT JOIN (SELECT id AS match_id, home_player_1 AS pid FROM Match WHERE season = '2015/2016' UNION ALL SELECT id, home_player_2 FROM Match WHERE season = '2015/2016' UNION ALL SELECT id, home_player_3 FROM Match WHERE season = '2015/2016' UNION A...
challenging
191
european_football_2
How many players had a jumping score of 80 or higher in the player fitness assessments made between 22 February 2007 and 30 August 2007, with both of those dates included in the period? For clarity, the jumping score is the player's jumping assessment on a 1-100 scale.
jumping score: the player's jumping assessment on a 1-100 scale
SELECT COUNT(DISTINCT player_api_id) AS player_count FROM Player_Attributes WHERE jumping >= 80 AND date(date) BETWEEN '2007-02-22' AND '2007-08-30'
challenging
192
european_football_2
What was KSV Cercle Brugge's build-up-play speed class at the time of their last match of the 2012/2013 season? The last match of the season is the latest-dated match the team played in that season, and the snapshot in effect at a moment is the latest one dated on or before that moment. I just want that single build-up...
Build-up-play speed class: a team's speed class for how quickly attacks are put together.
WITH last_match AS (SELECT MAX(m.date) AS match_day FROM Match m JOIN Team t ON t.team_api_id = m.home_team_api_id OR t.team_api_id = m.away_team_api_id WHERE t.team_long_name = 'KSV Cercle Brugge' AND m.season = '2012/2013'), effective AS (SELECT ta.buildUpPlaySpeedClass AS speed_class FROM Team_Attributes ta JOIN Tea...
challenging
193
european_football_2
I'm profiling how exceptional Landon Donovan was in the mid-2013 player ratings. By what percentage was his overall rating on 12 July 2013 higher than the average overall rating across all players on that same calendar date, considering every player with the overall rating they carried on that date (not only those upda...
Defensive work rate: a player's intensity of work in defense, rated low, medium or high. Overall rating: the overall score given to a player in the ratings.
WITH donovan AS (SELECT a.overall_rating AS r FROM Player p JOIN Player_Attributes a ON a.player_api_id = p.player_api_id WHERE p.player_name = 'Landon Donovan' AND a.date >= '2013-07-12' AND a.date < '2013-07-13'), inforce AS (SELECT a.player_api_id AS pid, a.overall_rating AS r, a.defensive_work_rate AS dwr FROM Play...
challenging
194
financial
Among female clients living in the district with the lowest average salary, give the account IDs of the oldest client and the difference between the highest and lowest district-average salaries.
WITH oldest AS (SELECT c.client_id FROM client AS c JOIN district AS d ON d.district_id = c.district_id WHERE c.gender = 'F' AND d.A11 = (SELECT MIN(A11) FROM district) ORDER BY c.birth_date, c.client_id LIMIT 1) SELECT DISTINCT a.account_id, (SELECT MAX(A11) - MIN(A11) FROM district) FROM oldest AS o JOIN disp AS x ON...
challenging
195
financial
In which district did the female client born on 1976-01-29 open her account?
SELECT DISTINCT d.A2 FROM client AS c JOIN disp AS x ON x.client_id = c.client_id JOIN account AS a ON a.account_id = x.account_id JOIN district AS d ON d.district_id = a.district_id WHERE c.gender = 'F' AND c.birth_date = '1976-01-29' ORDER BY d.A2
simple
196
financial
Among south Bohemia districts, in the one with the largest population, what percentage of resident clients are male? Round to two decimals.
WITH chosen AS (SELECT district_id FROM district WHERE A3 = 'south Bohemia' ORDER BY CAST(A4 AS INTEGER) DESC, district_id LIMIT 1) SELECT ROUND(100.0 * SUM(CASE WHEN c.gender = 'M' THEN 1 ELSE 0 END) / NULLIF(COUNT(*), 0), 2) FROM client AS c JOIN chosen AS d ON d.district_id = c.district_id
challenging
197
financial
For the account associated with the loan dated 1993-07-05, what was the percentage increase in its recorded balance from 1993-03-22 to 1998-12-27?
SELECT CAST((SUM(IIF(T3.date = '1998-12-27', T3.balance, 0)) - SUM(IIF(T3.date = '1993-03-22', T3.balance, 0))) AS REAL) * 100 / SUM(IIF(T3.date = '1993-03-22', T3.balance, 0)) FROM loan AS T1 INNER JOIN account AS T2 ON T1.account_id = T2.account_id INNER JOIN trans AS T3 ON T3.account_id = T2.account_id WHERE T1.date...
challenging
198
financial
For accounts opened from 1995 through 2000 in East Bohemia districts, list each account ID and its statement-issuance frequency.
SELECT T1.account_id, T1.frequency FROM account AS T1 INNER JOIN district AS T2 ON T1.district_id = T2.district_id WHERE T2.A3 = 'east Bohemia' AND STRFTIME('%Y', T1.date) BETWEEN '1995' AND '2000'
moderate
199
financial
For branch districts of accounts with loans still running in debt and recorded unemployment rates in both 1995 and 1996, list each district and the percentage change in its unemployment rate from 1995 to 1996, rounded to two decimal places.
Loan status 'D' denotes a running contract with the client in debt.
SELECT DISTINCT d.A2, ROUND(100.0 * (CAST(d.A13 AS DECIMAL(10, 2)) - CAST(d.A12 AS DECIMAL(10, 2))) / NULLIF(CAST(d.A12 AS DECIMAL(10, 2)), 0), 2) FROM loan AS l JOIN account AS a ON l.account_id = a.account_id JOIN district AS d ON a.district_id = d.district_id WHERE l.status = 'D' AND d.A12 <> 0 AND d.A13 IS NOT NULL...
challenging