当前位置: 代码迷 >> Sql Server >> 排序的时候,怎么让某个指定的记录排在第一,其他按时间排序
  详细解决方案

排序的时候,怎么让某个指定的记录排在第一,其他按时间排序

热度:98   发布时间:2016-04-27 15:46:16.0
排序的时候,如何让某个指定的记录排在第一,其他按时间排序!
谢谢大家!

比如在网页上传递某个id,让这个id的记录排在第一,其他按照时间倒序排列!

------解决方案--------------------
--假如ID為10
Order By (Case When ID = 10 Then 0 Else 1 End), 时间 Desc
------解决方案--------------------
select * from table order by case when id = 排在第一的列 then 0 else 1 end,时间字段 Desc
  相关解决方案