取得最大值的資料列 - ROW_NUMBER ()

摘要:取得最大值的資料列 - ROW_NUMBER ()

MSDN:

http://msdn.microsoft.com/zh-tw/library/ms186734.aspx#台灣(繁體中文)

 

ROW_NUMBER ( ) 
    OVER ( [ PARTITION BY value_expression , ... [ n ] ] order_by_clause )

EX:

 

SELECT STRSTORECODE
 , STRCASHADMINNO
 , row_number() OVER (PARTITION BY STRSTORECODE ORDER BY STRCASHADMINNO DESC) AS rn
 , DTMACCOUNT
FROM
C_CASHADMINHDR