SQL Server优先级排序 [英] SQL Server Priority Ordering

查看:519
本文介绍了SQL Server优先级排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含任务的表,我想根据任务的优先级给出这些明确的排序。我可以想到这样做的唯一方法是通过一个唯一的 int列,它将任务按照优先级排序(即1的前1000个是低)。



问题是,我想要更新任务并将其优先级设置为较低的值,我必须更新其当前值和其新值之间的所有其他行。



任何人都可以提出更好的方法来实现这一点?

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆