开发者

complex sorting sql

开发者 https://www.devze.com 2023-03-07 06:46 出处:网络
I have the following table PriorityTime 1001 863 852 I want to sort it by first by priority and then by time, however, priority differce within 20 points are treated the same. e.g.100 and 85 are

I have the following table

Priority  Time
100        1
 86        3
 85        2 

I want to sort it by first by priority and then by time, however, priority differce within 20 points are treated the same. e.g. 100 and 85 are considered as the same priority level. so the result will be:

Priority  Time
    100开发者_如何学Go        1
     85        2
     86        3 

Thanks,


Try this (assuming that priority is an integer)

select * 
from foobar
order by ( priority / 20 ) , -- 0-19 yields 0 , 20-39 yields 1, etc.
         time
0

精彩评论

暂无评论...
验证码 换一张
取 消