答案 0 :(得分:2)
select a.ID, SUM(a.points) from(select ID , points,row_number() over
(partition by ID order by POINTS) as rownum_returned from your_table) a where
a.rownum_returned<6 group by a.ID;
答案 1 :(得分:0)
如果我要这样做,我会用子查询解决它。 在SQL服务器中,我将执行检索5个较低点的子查询
Select Top 5 id, point from table
Order by point asc
注意:关键字TOP
将结果限制为前5个
注2:逐点asc
将命令结果置于最低值
现在我使用查询作为子查询来完成活动
Select id, sum (point) from
(Select top 5 id,point from table order by point asc) group by id
这应该有效