SQLize Online / PHPize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE inventory_player ( id int(11) NOT NULL AUTO_INCREMENT, user_id int(11) NOT NULL, item_id int(11) NOT NULL, slot_id int(11) NOT NULL, deleted_at_time datetime DEFAULT NULL, PRIMARY KEY (id) ); INSERT INTO inventory_player VALUES (1, 4, 0, 0, NULL), (2, 4, 0, 1, NULL), (3, 4, 0, 2, NULL), (4, 4, 0, 3, NULL), (5, 4, 1, 4, NULL), (6, 4, 1, 4, NULL), (7, 4, 1, 4, NULL), (8, 4, 1, 4, NULL); SELECT * FROM inventory_player order by id; WITH old as (SELECT *, ROW_NUMBER() OVER (order by id desc) rn FROM inventory_player) UPDATE inventory_player ip INNER JOIN old ON old.rn = ip.id SET ip.item_id = old.item_id, ip.slot_id = old.slot_id; SELECT * FROM inventory_player order by id;

Stuck with a problem? Got Error? Ask ChatGPT!

Copy Clear