1
$first = mysql_query("SELECT * FROM feeds ORDER BY (number1 + number2) DESC LIMIT 1");

这不起作用。number1 和 number2 都是 int 列。

有什么建议吗?

4

2 回答 2

1
SELECT * FROM feeds ORDER BY (select (sum(column1) + sum(column2)) from feeds) DESC LIMIT 1
于 2013-10-16T01:51:47.210 回答
0

你可以使用伪字段

SELECT *, (number1 + number2) as my_sum 
FROM feeds ORDER BY my_sum DESC LIMIT 1

可以使用AS alias_name为select_expr赋予别名。别名用作表达式的列名,可用于GROUP BYORDER BYHAVING子句。

http://dev.mysql.com/doc/refman/5.5/en/select.html

于 2013-10-16T01:53:22.483 回答