如果出现“要是后面的40条记录某一条在本周得分超过前面的20条记录的某一条记录的得分
将会取代该记录”总记录不是没有60条了吗,是不是记录一定要60条?用临时表吧,很方便的!把20条得分最多的记录排序插入#temp,然后,再把本周排序的不在#temp表中的前40条记录插入#temp后,select * from #temp就行了。

解决方案 »

  1.   

    select top 20 * from 表 where 上传时间<>'本周上传的作品' order by 上周得分 desc
    union all
    select top 40 * from 表 where 上传时间='本周上传的作品' order by 上传时间
      

  2.   

    select * from (select top 20 * from 表 where 上传时间<>'本周上传的作品' order by 上周得分 desc) tem1
    union all
    select * from (select top 40 * from 表 where 上传时间='本周上传的作品' order by 上传时间) tem2
      

  3.   

    select * from (select top 20 * from 表 tem where 上传时间<>'本周上传的作品' and 上周得分>(select 本周得分 from 表 where 上传时间='本周上传的作品' and 编号=tem.编号) order by 上周得分 desc) tem1
    union all
    select * from (select top 40 * from 表 where 上传时间='本周上传的作品' order by 上传时间) tem2
      

  4.   

    select top 20 * from 表 
     where datepart(wk, getdate()) <> datepart(wk, 上传时间) order by 上周得分 desc
    union all
    select top 40 * from 表 
     where datepart(wk, getdate()) <> datepart(wk, 上传时间) order by 上传时间
      

  5.   

    select top 60 * from yourtable a left join  (select top 20 a.id,max(得分) as 得分 from (select id,上周得分 as [得分] from  yourtable 
    union all (select id ,本周得分 as [得分] from  yourtable )) a 
    group by a.id order by 得分 desc) b on a.id=b.id
    order by case when a.id is null then 0 else 1 end desc,case when a.id is null then 0 else b.得分 end desc,a.上传时间