User's comments grouped by post

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

WITH commentStats AS (
    SELECT      COUNT (Id) AS numC,
                MAX (Id) AS dId,
                MAX (CreationDate) AS dDate,
                PostId
    FROM        Comments
    WHERE       UserId = ##UserId##
    GROUP BY    PostId
)
SELECT      CASE    WHEN p.PostTypeId = 1
                    THEN 'Q'
                    ELSE 'A'
            END
            AS [Q/A],
            cs.numC AS [Num Cmts],
            cs.dDate AS Latest,
            cs.PostId AS [Post Link],
            c.Text AS [Last Comment]
FROM        commentStats cs
INNER JOIN  Comments c
ON          c.Id = cs.dId 
INNER JOIN  Posts p 
ON          p.Id = cs.PostId
ORDER BY    cs.dDate DESC

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results