Roger Roger - 2 months ago 18
PHP Question

Sort Data MYSQL

Display result based on score DESC.

I have table with 4 columns, what I want is show result order by score DESC.

id t1 t2 t3 t4
----------------------
1 10 20 30 40
2 6 10 15 30


Sum of 4 columns and sort by DESC.

$q = "SELECT sum(t1+t2+t3+t4) AS point FROM scores ORDER BY point DESC"; //not working

Answer

Try it like this:

SELECT id, SUM(t1+t2+t3+t4) AS point
FROM scores
GROUP BY id
ORDER BY point DESC";
Comments