我在写:
Select datediff(hh,getutcdate(), End_Date) as "Duration"
from MasterTable
order by Duration
以递增顺序获得小时值的差异。我得到了输出,
Duration -------- -259 -210 5 10 22 35 75 105 235
但是我想要,必须根据正数和负数小时值来完成排序。所以,我需要输出:
Duration -------- 5 10 22 35 75 105 235 -259 -210
是否有任何调整来完成这样的任务?提前谢谢。
答案 0 :(得分:1)
如果您确实需要序列,正如您在问题中指出的那样,它首先按升序排列所有正数,那么负数按升序排列,则应为:< / p>
Select datediff(hh,getutcdate(),End_Date) as "Duration" from MasterTable
order by CASE WHEN Duration >= 0 THEN 0 ELSE 1 END,Duration
答案 1 :(得分:0)
了解您需要的是忽略持续时间标志:
尝试使用ABS:
Select datediff(hh,getutcdate(),End_Date) as "Duration" from MasterTable order by ABS(Duration)
答案 2 :(得分:0)
试试这个,
Select Abs(datediff(hh,getutcdate(),End_Date)) as "Duration" from MasterTable order by Abs(Duration)