user1569897
user1569897

Reputation: 437

how to push data down a row in sql results

I would like help with sql query code to push the consequent data in a specific column down by a row. For example in a random table like the following,

x column                y column
6                       6
9                       4
89                      30
34                      15

the results should be "pushed" down a row, meaning

x column                y column
6                       null or 0 (preferably) 
9                       6
89                      4
34                      30

Upvotes: 0

Views: 1058

Answers (3)

user4518487
user4518487

Reputation: 1

After taking a backup of you table: Make a PHP function that will: - Load all values of Y into an array - Set Y = 0 (MYSQL UPDATE) - load the values back from PHP array to MYSQL

Upvotes: 0

Mike Brant
Mike Brant

Reputation: 71414

I am not aware of a simple way to do this with the way you are showing the table being formatted. If your perhaps added two consecutively numbered integer fields that provide row number and row number + 1 values, you could join the table to itself and get that information.

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1270463

SQL tables have no inherent concept of ordering. Hence, the concept of "next row" does not make sense.

Your example has no column that specifies the order for the rows. There is no definition of next. So, what you want to do cannot be done.

Upvotes: 1

Related Questions