I'm making a profile page for a site that I'm making, and it there's a section to display 'Total Ratings', and the database structure I have is
username|song_id|plus|minus
---------------------------
example | 294398|001 | 000
egnum2! | 244202|000 | 001
So I need to count the amount of rows that contain a specified username and add them up, I can't find a MySQL command that I can understand too easily :S
Eg, I visit example's profile, and it counts all the number of times his name appears in the table example above, and give me a number, in the example above, example has 1 total rate by 'example' in the same way, i'll have to do another where I count all his plus ra开发者_JS百科tes and minus rates. (those are 1/0, I put in triple digits cause it wouldn't fit lol)
Use a GROUP BY
query and aggregate functions:
select username, count(*), sum(plus), sum(minus)
from your_table
where username = 'example'
group by username;
精彩评论