Having trouble with this query:
I have a table that has an entry for each battle a user has entered.
user_id | name | category | points
==================================
1 | user1 | battle1 | 4
54 | user2 | battle1 | 20
88 | user 8 | battle4 | 33
etc
There are 4 categories.
I hope I can explain this properly.
What I need to do is get the sum of each category for each user but also show the totals for that user from the other categories as well.
Right now I can query the sum of one category like this per user:
SELECT user_id, name, category, SUM(points)
FROM battle_points
WHERE user_id = id
GROUP BY category
But I don't want it per user. So if I do that query without the WHERE clause it's all messed up.
I need to have the top 10 ranks for each category. So it could be like this:
name | cat 1 | cat 2 | cat 3 | cat 4
=====================================
user1 | 33 | 0 | 49 | 5
user2 | 0 | 55 | 12 | 3
etc...
Any ideas?
Thanks.