1. 程式人生 > >T-SQL top 1 in group

T-SQL top 1 in group

語法:ROW_NUMBER() OVER(PARTITION BY COLUMN ORDER BY COLUMN)


example:

with cte AS
    (
       SELECT *,
             ROW_NUMBER() OVER (PARTITION BY ChartKey,WorkflowKey  ORDER BY EditDate DESC) AS rn
       FROM pins
    )
   
    SELECT    *
    FROM        cte
    WHERE     rn = 1