每天进步一点点之SQL 获取表中某个时间字段离当前时间最近的几条
实际中用到的SQL:
select * from (select top 3 Id,
case when startSignup>GETDATE() then ‘敬请期待‘ when (startSignup<GETDATE() and endsignUp>=getdate()) then ‘正在报名‘
when (StartDate<GETDATE() and EndDate>=GETDATE())or (StartDate<GETDATE() and EndDate is null) then ‘正在进行‘ when EndDate<GETDATE() then ‘已经结束‘ else ‘‘ end [status], Name,VerifyCode,StartDate, EndDate, TrainType, AddTime, CheckStatus, [Disable],StartSignup, EndSignup, SignupLimit,[Price] from Train A where A.CheckStatus=1
and A.[Disable]=0 and A.TrainType=1 and Name not like ‘%测试%‘ order by ABS(convert(float,A.StartDate-GETDATE())))B order by startdate desc,B.Enddate desc
关键字:order by ABS(convert(float,A.StartDate-GETDATE()))
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。