mardi 18 septembre 2018

MYSQL query that contains 2 things I need in 1 query

I have built a live scoring system for a game. When the scores are entered into the MySQL database, they are entered like this...

ID    userid    sessionid    sprintid    pointvalue1    pointvalue2  pointvalue3
1      1          1             1             10            5             2
2      2          1             1             10            5             3
3      3          1             1             12            6             3
4      1          1             2             10            6             4
5      2          1             2             12            5             3
6      3          1             2              9            4             3 

As you can see from the above, there is 1 session, 2 different sprints (iterations) and 3 different users. I want to display a leader board. The leader board would show (by iteration), user name (from another table), sprint, point value 1, point value 2, point value 3, sum of point value 1 cumulative for all iterations in that session. So on iteration 1, point value 1 and sum of point value 1 cumulative would be the same. But, in iteration 2, I should see a sum of point value 1 of 20 for user 1, 22 for user 2, and 21 for user 3, in the proper order (descending). I tried a subquery using a select sum, but couldn't quite get it right, and I tried a SUM(IF()), which seemed like it would be right, but it's not. I guess I need some guidance on which direction to go.

Aucun commentaire:

Enregistrer un commentaire