我有多次相同用户ID的表,在表中也是得分列 现在我想通过具有不同用户ID
的总分来获得不同用户订单的表总分的所有记录我正在尝试实施以下查询但不能正常工作
select contId,answer,question,ContributorsId,sum(TotalScore) TotalScore
from top_contributors
group by ContributorsId
order by TotalScore DESC
请注意contid是主键(自动增量),ContributorsId是userid谢谢
答案 0 :(得分:2)
它是一个简单的聚合查询
select contributorId,sum(score) totalscore
from top_contributors
group by contributorId
order by totalscore
答案 1 :(得分:1)
select tc.contributorId, sum(score) as totalscore
from top_contributors tc
group by contributorId
order by totalscore
我相信它应该有效。