SQL Server优先级排序 [英] SQL Server Priority Ordering
问题描述
问题是,我想要更新任务并将其优先级设置为较低的值,我必须更新其当前值和其新值之间的所有其他行。
任何人都可以提出更好的方法来实现这一点?
p>使用实数值作为优先级。您可以随时在两个现有值之间的值中滑动,例如 newPri = task1Pri +(task2Pri - task1Pri)/ 2
其中Task1具有较低优先级的数值(这可能是较高的优点)。
Corin指出,必须为插入优先级列表顶部或底部的任务计算最小和最大优先级。
Joelhardi提醒我们,重新排序流程是不时清理表格的好主意。
I have a table that contains tasks and I want to give these an explicit ordering based on the priority of the task. The only way I can think to do this is via an unique int column that indexes where the task is in term of the priority (i.e. 1 is top 1000 is low).
The problem is that say I wanted to update task and set its priority to a lower value , I would have to update all the other rows between its current value and its new value.
Can anyone suggest a better way of implementing this?
Use a real number value as the priority. You can always slide in a value between two existing values with something like newPri = task1Pri + (task2Pri - task1Pri)/2
where Task1 has the lower priority numeric value (which is probably the higher piority).
Corin points out that min and max priorities would have to be calculated for tasks inserted at the top or bottom of the priority list.
And joelhardi reminds us that a reorder process is a good idea to clean up the table from time to time.
这篇关于SQL Server优先级排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!