How to ORDER BY a SUM() in MySQL?

后端 未结 5 819
暗喜
暗喜 2020-11-27 19:12

I have a table: \"ID name c_counts f_counts \"

and I want to order all the record by sum(c_counts+f_counts) but this doesn\'t work:

SELECT

5条回答
  •  伪装坚强ぢ
    2020-11-27 19:14

    Without a GROUP BY clause, any summation will roll all rows up into a single row, so your query will indeed not work. If you grouped by, say, name, and ordered by sum(c_counts+f_counts), then you might get some useful results. But you would have to group by something.

提交回复
热议问题