I have the following table
ID | NOME | ANO | REGISTO
----------------------------------
0 A 2015 4
1 B 2017 6
2 C 2014 15
3 D 2017 2
4 E 2013 55
5 F 2017 1
6 G 2017 6
7 H 2017 8
And doing the following query I get the result:
SELECT * FROM exemplo WHERE ano = 2017 ORDER BY nome ASC
ID | NOME | ANO | REGISTO
----------------------------------
1 B 2017 6
3 D 2017 2
5 F 2017 1
6 G 2017 6
7 H 2017 8
I want to make a UPDATE
that increments the value of REGISTO
starting with 1 according to alphabetical ordering. That is:
ID | NOME | ANO | REGISTO
----------------------------------
1 B 2017 1
3 D 2017 2
5 F 2017 3
6 G 2017 4
7 H 2017 5
And repeating the process over the years the end result would be:
SELECT * FROM EXEMPLO ORDER BY id
ID | NOME | ANO | REGISTO
----------------------------------
0 A 2015 1
1 B 2017 1
2 C 2014 1
3 D 2017 2
4 E 2013 1
5 F 2017 3
6 G 2017 4
7 H 2017 5
I am questioning the process only through SQL, without programming language support.