Frank
Frank

Reputation: 7585

complex sorting sql

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        1
     85        2
     86        3 

Thanks,

Upvotes: 1

Views: 185

Answers (1)

Nicholas Carey
Nicholas Carey

Reputation: 74197

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

Upvotes: 5

Related Questions