現有資料展示如下,我想快速的以bl_comp 分組,對每個分組都從1自然增長計數,只需一條語句就可以搞定
SELECT *, ROW_NUMBER() OVER (PARTITION BY bl_comp ORDER BY bl_comp ,bl_key ) NewIndex
SELECT *, ROW_NUMBER() OVER (PARTITION BY bl_comp ORDER BY bl_comp ,bl_key ) NewIndex
FROM Tb_Balance_all_20161019
bl_comp bl_key bl_account bl_cur bl_port bl_scomp bl_shop bl_dept bl_staf bl_pn bl_flag
1HF 1 200700000002 CRRMB03 NULL NULL NULL NULL NULL NULL 0
1HF 3 200700000005 CRRMB03 NULL NULL NULL D1HF02 NULL NULL 0
1HF 4 200700000005 CRRMB03 NULL NULL NULL D1HF04 NULL NULL 0
1HF 6 200700000016 CRRMB03 NULL NULL NULL D1HF03 NULL NULL 0
886 6 200700000002 CRRMB03 NULL NULL NULL NULL NULL NULL 0
886 7 200700000005 CRRMB03 NULL NULL NULL D1HF02 NULL NULL 0
886 9 200700000005 CRRMB03 NULL NULL NULL D1HF04 NULL NULL 0
886 13 200700000016 CRRMB03 NULL NULL NULL D1HF03 NULL NULL 0