Reputation: 39
I have query:
SELECT * FROM members ORDER BY ( firstColumn / anotherColumn ) DESC
Now I'm printing this:
return $query['firstColumn'] / $query['anotherColumn'];
Is it possible to print divided result without any php tricks? For example return $query['dividedColumns'];
Upvotes: 0
Views: 92
Reputation: 72
You can try this
SELECT *, (firstColumn/anotherColumn) AS dividedColumns FROM members ORDER BY ( firstColumn / anotherColumn ) DESC
Upvotes: 0
Reputation: 26450
You can do it directly in the query, and use that result as the ORDER BY
argument too.
SELECT *, firstColumn/anotherColumn as dividedColumns
FROM members
ORDER BY dividedColumns DESC
Now you can use it as $query['dividedColumns']
in PHP.
Upvotes: 1
Reputation: 2522
Column Alias will solve your problem, you can change your query to:
SELECT members.*,
( firstColumn / anotherColumn ) AS `divided_amount`
FROM members
ORDER BY divived_amount DESC;
Upvotes: 2