首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

!sql server order by 有关问题

2012-01-12 
求助!sql server order by 问题select...from...where...ORDERBYSUB_TENPDESC,CHNG_DATEDESC,CASEWHENDEL_

求助!sql server order by 问题
select   ...   from   ...where...
ORDER   BY           SUB_TENP   DESC,   CHNG_DATE   DESC,  
CASE   WHEN   DEL_DATE   IS   NULL   THEN   DEL_DATE   ASC   ELSE   DEL_DATE   DESC   END,   TENP_KN   DESC

[解决办法]
order by 只能放在最后
[解决办法]
我猜你的意思是

order by ORDER BY SUB_TENP DESC, CHNG_DATE DESC,
CASE WHEN DEL_DATE IS NULL THEN '2999-01-01 ' ELSE DEL_DATE END DESC,
TENP_KN DESC

[解决办法]
case when 不能用到order by 里

select ...,CASE WHEN DEL_DATE IS NULL THEN DEL_DATE ASC ELSE DEL_DATE DESC END as newfield from ...where...
ORDER BY SUB_TENP DESC, CHNG_DATE DESC,
newfield desc, TENP_KN DESC
[解决办法]
试一下,原来可以放在order by 后面,只是你写错了(以前从来没这么写过)

select ... from ...where...
ORDER BY SUB_TENP DESC, CHNG_DATE DESC,
CASE WHEN DEL_DATE IS NULL THEN DEL_DATE ASC ELSE DEL_DATE DESC END, TENP_KN DESC

“DESC END” 应该反过来啊 “END DESC”
select ... from ...where...
ORDER BY SUB_TENP DESC, CHNG_DATE DESC,
CASE WHEN DEL_DATE IS NULL THEN DEL_DATE ASC ELSE DEL_DATE END DESC , TENP_KN DESC

热点排行