Q:

sql server selecting sum of each record having same id

I am having table as below..
r_Id     Marks
1         25
1         25   
1         25
2         30
2         30  

now i want a query in which sum of marks for each r_id should be calculated and result should be
r_Id     Sum
 1       75   
 2       60

Without  using cursor or looping in sql server 2008. Please help me out to do it.

A:

Please try:
SELECT 
    r_Id, 
    SUM(Marks) AS [Sum] 
FROM 
    YourTable 
GROUP BY r_Id

OR
SELECT DISTINCT
    r_Id, 
    SUM(Marks) OVER(PARTITION BY r_Id) AS [Sum] 
FROM 
    YourTable

A:

This should do it
SELECT r_Id, SUM(Marks) AS [Sum] 
FROM SomeTable 
GROUP BY r_Id;
GO

I hope this helps.

