ROW_NUMBER() OVER( ) html
ROW_NUMBER() OVER( PARTITION BY pkid ORDER BY id) --函數分組,而且排序
PARTITION BY pkid -- 按照pkid 分組
ORDER BY id -- 按照id 排序
--示例:先用pkid分組,分組和在用id排序
SELECT ROW_NUMBER() OVER( PARTITION BY pkid
ORDER BY id ) AS a , pkid,id FROM
dept WHERE id = 1
--不一樣的pkid分組以後一致排序都是1,相同的pkid,用id排序
/*
a pkid id
1 CLBX20180413005 47
1 CLBX201804130053 39
2 CLBX201804130053 46
1 RCBX201803210369 38
*/
後期持續跟新,若有錯誤之處,請你們指出!函數
SQL Server 經常使用函數使用方法(持續更新)
http://www.javashuo.com/article/p-duzhlqbv-cg.html spa