1

我想按此规则对 MySQL 查询进行升序:x-y/x

x = 价格

y = 价格2

price 和 price2 是 MySQL 表中的列。

我有这个查询,但不幸的是不起作用。

SELECT * 
FROM albums 
WHERE price2 > 1 
ORDER BY price - price2 / price ASC

感谢关注。

4

3 回答 3

4

试试这个:

$SQLquery = "SELECT * FROM albums WHERE price2 > 1 ORDER BY (price-price2)/price ASC";

或者

$SQLquery = "SELECT * FROM albums WHERE price2 > 1 ORDER BY ((price-price2)/price) ASC";
于 2012-04-23T15:20:11.550 回答
3

你应该试试:

SELECT * FROM albums 
WHERE price2 > 1 
ORDER BY ((price - price2) / price) ASC

或者

SELECT albums.*, ((price - price2) / price) myvar FROM albums 
WHERE price2 > 1 
ORDER BY myvar ASC
于 2012-04-23T15:13:32.740 回答
0

Order By 根据指定的列工作。您可以从包含基于该公式的值的新列的基表创建视图或临时表,然后对该列进行排序。

于 2012-04-23T15:14:16.520 回答