I have usual 'id' in my table, but I also need a 'code', which would be like id, but year specific. That means it will be somehow auto-increment, but will start with 1 for each new year. When I insert new row, I simply use
SELECT MAX(code) WHERE YEAR(time) = YEAR(CURRENT_DATE)
and increment by one.
But my project is already running and I would like to have a query, which would set these codes for already existing rows.
So now my table looks like this ->
Text 2011 'NULL' || Text 2011 'NULL' || Text 2011 'NULL' || Text 2012 'NULL' || Text 2012 'NULL'
and I need to change it to
Text 2011 1 || Text 2011 2 || Text 2011 3 || Text 2012 1 || Text 2012 2
Any ideas?