Gets: Score, Age, Views, and Anonymous Feedback for a specific post and any answers it may have. (If given an answer-post ID, it just fetches data for that answer.)
Q&A for students, teachers, polyglots, and anyone interested in the techniques of second-language acquisition
DECLARE @PostId INT = ##PostId##; WITH AnonVoteCounts AS ( SELECT pf.Id , SUM (CASE WHEN pf.VoteTypeId = 2 THEN 1 ELSE 0 END) AS Helpful , SUM (CASE WHEN pf.VoteTypeId = 3 THEN 1 ELSE 0 END) AS Unhelpful FROM PostFeedback pf GROUP BY pf.Id ) SELECT p.Id AS [Post Link] , CASE p.PostTypeId WHEN 1 THEN 'Q' WHEN 2 THEN 'A' ELSE '?' END AS [Q/A] , p.Score , avc.Helpful , avc.Unhelpful , p.ViewCount , CONVERT (VARCHAR(25), p.CreationDate, 100) FROM Posts p LEFT JOIN AnonVoteCounts avc ON p.Id = avc.Id WHERE p.Id IN ( SELECT q.id FROM Posts q WHERE q.id = @PostId UNION ALL SELECT a.Id FROM Posts a WHERE a.ParentId = @PostId ) ORDER BY P.Id