T-SQL Tuesday #168 : Row_Number/Rank/Dense_Rank

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

SELECT TOP (20) Title, CreationDate, Score,
    [row_number] = ROW_NUMBER() OVER (ORDER BY Score DESC),
    [rank]       = RANK()       OVER (ORDER BY Score DESC),
    [dense_rank] = DENSE_RANK() OVER (ORDER BY Score DESC)
  FROM Posts 
  WHERE PostTypeId = 1 -- Question
  AND CreationDate >= DATEFROMPARTS(YEAR(GETDATE()),MONTH(GETDATE()),1)
  ORDER BY Score DESC;

Enter Parameters

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