order by name,updatetime desc 这样是不行的 结果就是 title updatetime name ----------------------------------------------- xx 2005-1-8 base xx 2005-1-2 base xx 2005-1-3 carb xx 2005-1-8 econ xx 2005-1-2 econ xx 2005-1-5 prec 这个排序结果不是我想要的
order by (case when exists(select 1 from 表 where name=a.name and updatetime<>a.updatetime) then (select top 1 updatetime from 表 where name=a.name order by updatetime desc) else updatetime end),name,updatetime
order by (case when exists(select 1 from 表 where name=a.name and updatetime<>a.updatetime) then (select top 1 updatetime from 表 where name=a.name order by updatetime desc) else updatetime end),name,updatetime这个是可以的,但是排序结果是updatetime升序排列,我的意思是updatetime最后的放在输出结果最顶端,不管是否有重复。
order by (case when exists(select 1 from 表 where name=a.name and updatetime<>a.updatetime) then (select top 1 updatetime from 表 where name=a.name order by updatetime desc) else updatetime end) desc,updatetime desc
谢谢lsxaa(小李铅笔刀) ( ) 问题解决了,不过应该是 order by (case when exists(select 1 from 表 where name=a.name and updatetime<>a.updatetime) then (select top 1 updatetime from 表 where name=a.name order by updatetime desc) else updatetime end) desc,name desc,updatetime desc 不过我还想问一下,这个排序是啥意思??
这样是不行的
结果就是
title updatetime name
-----------------------------------------------
xx 2005-1-8 base
xx 2005-1-2 base
xx 2005-1-3 carb
xx 2005-1-8 econ
xx 2005-1-2 econ
xx 2005-1-5 prec 这个排序结果不是我想要的
from 表
where name=a.name and updatetime<>a.updatetime)
then (select top 1 updatetime
from 表
where name=a.name order by updatetime desc)
else updatetime
end),name,updatetime
order by (case when exists(select 1
from 表
where name=a.name and updatetime<>a.updatetime)
then (select top 1 updatetime
from 表
where name=a.name order by updatetime desc)
else updatetime
end),name,updatetime这个是可以的,但是排序结果是updatetime升序排列,我的意思是updatetime最后的放在输出结果最顶端,不管是否有重复。
from 表
where name=a.name and updatetime<>a.updatetime)
then (select top 1 updatetime
from 表
where name=a.name order by updatetime desc)
else updatetime
end) desc,updatetime desc
问题解决了,不过应该是
order by (case when exists(select 1
from 表
where name=a.name and updatetime<>a.updatetime)
then (select top 1 updatetime
from 表
where name=a.name order by updatetime desc)
else updatetime
end) desc,name desc,updatetime desc
不过我还想问一下,这个排序是啥意思??