instruction: Rep earned on answers to questions closed within a day. Calculates total reputation earned on answers to questions which were closed within 24 hours of creation for the year of 2013. Reptuation is grouped by user id.
response: SELECT Answers.OwnerUserId, SUM(CASE WHEN Votes.VoteTypeId = 2 THEN 10 WHEN Votes.VoteTypeId = 3 THEN -2 ELSE 0 END) AS EarnedRep FROM Posts AS Questions, Posts AS Answers, Votes WHERE Questions.PostTypeId = 1 AND Questions.CreationDate BETWEEN '2013-01-01' AND '2013-12-31' AND CAST((JULIANDAY(ClosedDate) - JULIANDAY(Questions.CreationDate)) * 24.0 AS INT) < 24 AND Answers.PostTypeId = 2 AND Answers.ParentId = Questions.Id AND Votes.PostId = Answers.Id GROUP BY Answers.OwnerUserId