PHP MySQL返回分割结果

时间:2017-04-12 15:32:18

标签: php mysql divide

我有疑问:

SELECT * FROM members ORDER BY ( firstColumn / anotherColumn ) DESC

现在我打印这个:

return $query['firstColumn'] / $query['anotherColumn'];

是否可以在没有任何php技巧的情况下打印分割结果?例如return $query['dividedColumns'];

3 个答案:

答案 0 :(得分:2)

列别名将解决您的问题,您可以将查询更改为:

SELECT members.*, 
      ( firstColumn / anotherColumn ) AS `divided_amount`  
FROM members 
ORDER BY divived_amount DESC;

答案 1 :(得分:1)

您可以直接在查询中执行此操作,并将该结果用作ORDER BY参数。

SELECT *, firstColumn/anotherColumn as dividedColumns 
FROM members 
ORDER BY dividedColumns DESC

现在,您可以在PHP中将其用作$query['dividedColumns']

答案 2 :(得分:0)

你可以试试这个

SELECT *, (firstColumn/anotherColumn) AS dividedColumns FROM members ORDER BY ( firstColumn / anotherColumn ) DESC