当我从表中删除某些行时,删除后会显示如下表:
+-----+--------+----------+
| ID | Name | Address |
+-----+--------+----------+
| 1 | name1 | address1 |
| 2 | name2 | address2 |
| 8 | name8 | address8 |
| 9 | name9 | address9 |
+-----+--------+----------+
问题是ID
未正确订购
我需要像这样重新排序:
+----+---------+----------+
| ID | Name | Address |
+----+---------+----------+
| 1 | name1 | address1 |
| 2 | name2 | address2 |
| 3 | name8 | address8 |
| 4 | name9 | address9 |
+-----+--------+----------+
是否有命令重新排序列,如图所示?
我正在使用sqlite
答案 0 :(得分:0)
我认为这种类型的查询应该这样做:
UPDATE yourTable
SET ID = (SELECT COUNT(*) FROM yourTable ti WHERE ti.ID <= yourTable.ID)