34,590
社区成员
发帖
与我相关
我的任务
分享
select * from tb order by case when istop = 1 and (topdate is null or topdate < getdate()) then 1 else 2 end , postdate
--id自增,换成ID
select * from tb order by case when istop = 1 and (topdate is null or topdate < getdate()) then 1 else 2 end , [ID]
ORDER BY (CASE [istop] WHEN TRUE THEN 1 ELSE 2 END),
(CASE [topdate] WHEN NULL THEN 1 ELSE 2 END),--你的“topdate <DateTime.Now”這個條件是多餘的
[postdate]
select * from [News] order by case when istop = 1 and (topdate is null or topdate < getdate()) then 1 else 2 end , postdate desc
select * from tb order by case when istop = 1 and (topdate is null or topdate < getdate()) then 1 else 2 end , postdate
select *
from table
order by case when XXXX then XX else XX end