A
A
Alexey2020-05-31 00:08:01
MySQL
Alexey, 2020-05-31 00:08:01

How to number fields in a rule in MYSQL?

There are lines, they need to be numbered: first, last, second, penultimate, third, penultimate and so on
Example:
1
3
5
7
6
4
2

How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Gordinskiy, 2020-05-31
@DmitriyGordinskiy

Cycle from the last element to the first, alternately adding each subsequent element to the beginning of the resulting list, then to the end (in this case, the first action is determined depending on the parity of the total number of elements.

N
noremorse_ru, 2020-06-01
@noremorse_ru

You know the number of elements in the array, iterate each element and assign Count() - n, where n is the current iteration. Well and to do it certainly not means SQL.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question