MySQL incrementing value

后端 未结 5 1522
情话喂你
情话喂你 2020-12-14 15:20

Is there a way to make a value increment with every insert if having multiple inserts? (I dont speak of the primary key that autoincrements)

Lets say I have a struct

5条回答
  •  旧时难觅i
    2020-12-14 16:14

    Purely to add to @Bohemians answer - I wanted the counter to reset every so often and this can be done like such:

    SELECT *,(@position := IF (@position >= 15,1,@position + 1))

    Where 15 is obviously the maximum number before reset.

提交回复
热议问题