Q&A about the site for anime and manga fans
SELECT q.Id AS QuestionId, q.CreationDate AS QuestionCreationDate, q.Score AS QuestionScore, a.Id AS AnswerId, a.CreationDate AS AnswerCreationDate, a.Score AS AnswerScore, DATEDIFF(second, q.CreationDate, a.CreationDate) AS TimeDifferenceInSeconds, -- Time difference in seconds q.OwnerUserId AS UserID, (q.Score + a.Score) AS GainedUpvotes FROM Posts AS q JOIN Posts AS a ON q.Id = a.ParentId WHERE q.PostTypeId = 1 -- 1 indicates questions AND a.PostTypeId = 2 -- 2 indicates answers AND q.OwnerUserId = a.OwnerUserId -- same User ID AND DATEDIFF(second, q.CreationDate, a.CreationDate) < 3 -- answered themself in less that 3 seconds