User's comments grouped by post


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,
    FROM        Comments
    WHERE       UserId = ##UserId##
    GROUP BY    PostId
SELECT      CASE    WHEN p.PostTypeId = 1
                    THEN 'Q'
                    ELSE 'A'
            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

Switch sites:
loading Hold tight while we fetch your results