This is my Table
################################
# id_formfield # ID # int_Sort #
################################
# 1 # 1 # 2 #
# 2 # 1 # 3 #
# 3 # 1 # 4 #
# 4 # 1 # 4 #
# 5 # 1 # 4 #
# 6 # 2 # 1 #
# 7 # 2 # 3 #
# 8 # 2 # 3 #
# 9 # 2 # 4 #
As you can see my int_sort column is messed up somehow with equal numbers and I wanna to make it sequence with row number and reset row number when ID changes.
this should be result:
############################################
# id_formfield # ID # int_Sort # rownumber #
############################################
# 1 # 1 # 2 # 1 #
# 2 # 1 # 3 # 2 #
# 3 # 1 # 4 # 3 #
# 4 # 1 # 4 # 4 #
# 5 # 1 # 4 # 5 #
# 6 # 2 # 1 # 1 #
# 7 # 2 # 3 # 2 #
# 8 # 2 # 3 # 3 #
# 9 # 2 # 4 # 4 #
Edit : id_formfield is my primary key and order by int_sort ascending
Following script should get you started. In a nutshell, the script
IDENTITYcolumn to serve as rownumberMIN(Rownumber)for eachIDto get an offset.JOINthe temp table with the calculated offsets to restart the count for each group.SQL Statement
Test script