SQL Getting the N most recent rows over multiple grouping


Example

Given this data

User_IDCompletion_Date
12016-07-20
12016-07-21
22016-07-20
22016-07-21
22016-07-22
;with CTE as
(SELECT *, 
        ROW_NUMBER() OVER (PARTITION BY User_ID 
                           ORDER BY Completion_Date DESC) Row_Num
FROM    Data)
SELECT * FORM CTE WHERE Row_Num <= n

Using n=1, you'll get the one most recent row per user_id:

User_IDCompletion_DateRow_Num
12016-07-211
22016-07-221