select row_number() over(order by sum([count]) desc) as 排名,artid,sum([count]) as 总和
from tb
where datediff(dd,times,getdate()) between 0 and 2
group by artid
order by sum([count]) desc
select artid,count_sum,
(
select SUM(1)
from
(
select artid,SUM(count)as count_sum
from orders
where datediff(dd,times,getdate()) between 0 and 2
group by artid
) as b
where a.count_sum>=b.count_sum
) as ranks
from
(
select artid,SUM(count)as count_sum
from orders
where datediff(dd,times,getdate()) between 0 and 2
group by artid
) as a
------其他解决方案-------------------- select row_number() over(order by sum([count]) desc) as 排名,artid,sum([count]) as 总和from tbwhere datediff(dd,times,getdate()) between 0 and 2group by artidorder by sum([count]) desc ------其他解决方案--------------------