开发者

MySQL php - adding three datas and order by

OK so let's say I have three fields called "mines, explodes, and tags" in a table. I want to add those three together and say they are the "kills" ad开发者_StackOverflow社区ded up from the 3 fields and order them from highest to lowest (DESC). Is that possible?


Yes that will work! (But it won't be efficient.)

SELECT *, mines + explodes + tags AS kills
FROM your_table
ORDER BY kills DESC

If performance is a concern you should store the total as a column in the table and add an index to that column so that order by can use this index.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜