php - How to get SUM of only highest score in mysql and sort by category? -


what want sum of highest score in database , sort category

here database table

question_id  score1 score2 score3 category_id  -----------  ------ ------ ------ -----------    1           4      3       1        1    2           5      2       9        2    3           7      2       1        1    4           1      5       6        2 

what want in result

it highest score add category_id 1 = score 11 (7+4) category_id 2 = score 15 (9+6) 

any idea how solve using php or mysql?

thanks

you need greatest function that; returns biggest of sums respective group.

select category_id, greatest(sum(score1), sum(score2), sum(score3)) mytable group category_id; 

btw, different calculating sum of each greatest value per row. that, need reverse greatest , sum.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -