簡單說明如下:
ROW_NUMBER():資料列以流水編排序
RANK():資料列依ORDER BY欄位排名
DENSE_RANK():同RANK(),但不跳號
NTILE():資料列依傳入參數作為分組組數分組排名
--語法 select D.SHNo,D.SHSeq,SHSeqSub, ROW_NUMBER() OVER(PARTITION BY D.CorpNo,D.SHNo ORDER BY D.SHNo,D.SHSeq) AS ''ROW_NUMBER()'', RANK() OVER(PARTITION BY D.CorpNo,D.SHNo ORDER BY D.SHNo,D.SHSeq) AS ''RANK()'', DENSE_RANK() OVER(PARTITION BY D.CorpNo,D.SHNo ORDER BY D.SHNo,D.SHSeq) AS ''DENSE_RANK()'', NTILE(2) OVER(PARTITION BY D.CorpNo,D.SHNo ORDER BY D.SHNo,D.SHSeq) AS ''NTILE()'' from STKPackInsD D where CorpNo='20001' and SHNo IN ('HD130415025','HD130417041') order by D.SHNo,D.SHSeq,SHSeqSub
--結果
沒有留言:
張貼留言