In a database I have the following problem:
ID premio ordenar precio Fecha escala_Vencida
1 1 1 1000 30-12-2016 si
2 1 2 2000 30-12-2016 si
3 1 3 3000 30-12-2016 si
4 2 4 4000 30-12-2016 si
5 2 5 5000 30-12-2016 si
6 2 6 6000 30-12-2016 si
7 3 1 6000 30-1-2017 no
8 3 2 4000 30-1-2017 no
9 3 3 5000 30-1-2017 no
10 4 4 1000 30-1-2017 no
11 4 5 2000 30-1-2017 no
12 4 6 3000 30-1-2017 no
I need to make the reward is ordered the problem is the culumna (order) I need to make the number smaller to greater from 1 to infinity as long as the scale is not valid, that is to say it is marked (NO) and the price is lower a major, said in this case the number 6 represent 2 different prizes, in the case of the first prize the order is OK (from ID 1 to 6) but the second is messy (from ID 7 to 12) the second prize I need to insert it in an orderly way using a MySQL insert.
INSERT INTO TABLE
(
premio,
ordenar,
precio,
fecha,
escala_vencida,
)
VALUES
(
premio,
ordenar,<--- problema al ordenar
precio,
fecha,
escala_vencida,
)
IMPORTANT the ID is UNIQUE is not repeated throughout the Table.
Obviously this should do from a SELECT and detail is that I do not know how to order it from what I mentioned above.