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 [其他解释]
版主,你是用什么数据库的。 [其他解释]
[其他解释] 我的是access2003 [其他解释]
那该如何能得到想要的结果呢 [其他解释] 如何选出artid不重复呢? [其他解释]
Select Distinct a.artid,sum(a.counts) as 总数,b.title as titles From orders a inner join art b on a.artid=b.id where a.times>=Now()-7 and typ='a' group by a.artid,b.title