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
Post a Comment