T-SQL Tuesday #168 - Top N Per Group example 1

0

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 src AS
(
  SELECT Id, Title, CreationDate, OwnerUserId,
    rn = ROW_NUMBER() OVER 
    (
      PARTITION BY OwnerUserId
      ORDER BY CreationDate DESC
    )
  FROM Posts
  WHERE PostTypeId = 1 -- Question
  AND OwnerUserId IN (61305, 22656) -- me, Jon Skeet
)
SELECT Id, Title, CreationDate, OwnerUserId
  FROM src
  WHERE rn = 1;

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results