Skip to content
Advertisement

Insert ordinal number

MySQL 5.7

Consider the following sample data:

DB Fiddle of same: https://www.db-fiddle.com/f/7fAx1waY3TwjR34PanBkkv/0

With the query below, I get the following result:

In the new_file_name column, I want to insert an ordinal number in place of x. It should start at 1 for every new sku.

Wanted result:

Advertisement

Answer

Using a variable that holds a number that increments for every row.

When is_default = 1, the number gets reset.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement