douxun4173 2015-08-24 17:24 采纳率: 0%
浏览 70

mysql AUTO_INCREMENT基于另一列

How can I auto increment id column based on the 0 to max (int) value on the price column.

Lets assume that price is ASC, I want the id = 1 increment to start at the $0 mark. What would I have to edit for this code ALTER TABLE table AUTO_INCREMENT = 1 ?

id | price | other columns 
1  | 9
2  | 1
3  | 2
4  | 5

into

id | price | other columns
1  | 1
2  | 2
3  | 5
4  | 9
  • 写回答

4条回答 默认 最新

  • dongyuchen0214 2015-08-24 17:50
    关注

    A easy Way ist to create a new table with one column more with autoincrement.

    intert into newtable select '',o.* from oldtable o order by o.price asc;
    

    Then they insert all row in the right order from price in the new table.

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计