Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more: , +
i have table for store the rating:

TableName: Rates

ID Rating
1  4
2  5
1  3
2  4
3  4
2  3


I want to count the total rating by id and store the another table using asp.net-C#
Posted
Updated 31-Mar-15 5:58am
v2
Comments
ZurdoDev 31-Mar-15 10:38am    
SELECT COUNT(*), ID
FROM Rates
GROUP BY ID

Is that all you want? That gives you how many records of each ID are in the table.
F-ES Sitecore 31-Mar-15 11:43am    
or maybe

SELECT ID, SUM(rating) as TotalRating FROM Rates ORDER BY ID
ZurdoDev 31-Mar-15 11:44am    
Ya, OP said "count total". Could be anything. :)
Maciej Los 31-Mar-15 12:00pm    
Yeah, but "total by id". Looks good to me ;)

1 solution

create a new table and insert those values from old table Group by ID's
SQL
insert into  Ratings1(ID, rating )SELECT ID, SUM(rating) as TotalRating FROM Rates ORDER BY IDSELECT ID, SUM(rating) as TotalRating FROM Rates Group BY ID




learn it.

http://www.w3schools.com/sql/sql_insert_into_select.asp[^]


http://www.w3schools.com/sql/sql_groupby.asp[^]
 
Share this answer
 
Comments
Maciej Los 31-Mar-15 11:59am    
Why, King, why another table?
King Fisher 31-Mar-15 12:04pm    
Op said that " store the another table "
Maciej Los 31-Mar-15 12:06pm    
It might be anything... ;)
King Fisher 31-Mar-15 12:10pm    
anything? Am i understand anything wrong? I don't know ,i just answered this to remove from unanswered queue.I know its solved in Comment section , ha ha ha..
Maciej Los 31-Mar-15 12:21pm    
No, everything is fine ;)
Upvoted ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900