开发者

MySQL php - adding three datas and order by

开发者 https://www.devze.com 2023-01-26 14:02 出处:网络
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 fiel

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

精彩评论

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