Best way to store sort order/priority?

I'm using MySQL. I have a table where I need to be able to sort manually set the priority/order of the rows. I had originally thought of assigning each row an arbitrary order (1, 2, 3, etc.), then just "swapping" the order with the row being moved, but I don't think this is the best way to do it.

After doing some reading at related questions on here (like this one), a lot of people have said to assign a value to the priority column based off the id column (id * 1000). And to rearrange the rows, you would divide/subtract the difference between the columns. I don't quite understand how this works.

This is the layout of the table I need to sort.

CREATE TABLE liability_detail (
   id int NOT NULL AUTO_INCREMENT,
   analysis_id int NOT NULL, //(many-to-one relationship with analysis table)
   other_columns various datatypes
   sequence int DEFAULT 0
)

I'd like to setup an easy way to manage the priority of rows so I can easily sort them without having to write a lot of code to manage everything.


I ended up following the advice in this question: https://stackoverflow.com/a/6804302/731052

I set the sort-order column = id * 1000 so I could get unique orders. So far this works very well and haven't had any problems with it.

链接地址: http://www.djcxy.com/p/10982.html

上一篇: 定向梯度直方图vs边缘定位直方图

下一篇: 存储排序顺序/优先级的最佳方法?