------解决方案-------------------- 那不是 select* from tablename order by bbsanswerbatchid ,bbs…***time ------解决方案-------------------- select * from tb order by bbsanswerbatchid ,bbsanswersendtime ------解决方案-------------------- 你这个数据列bbsanswerbatchid就象NEWID()一样,应该是没有相同的数据吧?看你的要求好象没有什么特殊的呢 ------解决方案-------------------- 第一行跟第三个就是重复的,倒数第二个跟倒数第四个也是一样的 应该是个字表,有对应的主表的ID是唯一的吧 ------解决方案--------------------
select bbsanswerbatchid,bbsanswersendtime from ( SELECT *, case when (count(*) over(partition by bbsanswerbatchid)) > 1 then 1 else 0 end as bbsanswerbatchid_flag FROM tabl )t ORDER BY bbsanswerbatchid_flag desc,bbsanswersendtime
------解决方案-------------------- 我试了一下,应该是可以的:
;with tabl(bbsanswerbatchid,bbsanswersendtime) as ( select 'abc','2013-01-09' union all select 'abc','2013-01-10' union all select 'def','2013-09-01' union all select 'fgh','2013-09-10' )
select bbsanswerbatchid,bbsanswersendtime from ( SELECT *, case when (count(*) over(partition by bbsanswerbatchid)) > 1 then 1 else 0 end as bbsanswerbatchid_flag FROM tabl )t ORDER BY bbsanswerbatchid_flag desc,bbsanswersendtime /* bbsanswerbatchid bbsanswersendtime abc 2013-01-09 abc 2013-01-10 def 2013-09-01 fgh 2013-09-10 */