排序数据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

Try it like this:

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

This should work:

 $q = "SELECT t1+t2+t3+t4 AS point FROM scores ORDER BY t1+t2+t3+t4 DESC"; 

You need a GROUP BY clause.

SELECT SUM(t1+ t2+ t3+ t4) as sum_t FROM point GROUP BY id ORDER BY sum_t DESC;

You cannot use SUM() without a GROUP BY clause.

But it seems you really don't want to use SUM() at all, as the result you are looking for, is a simple addition:

SELECT (t1+t2+t3+t4) AS point FROM scores ORDER BY point DESC