我想按此规则对 MySQL 查询进行升序:x-y/x
x = 价格
y = 价格2
price 和 price2 是 MySQL 表中的列。
我有这个查询,但不幸的是不起作用。
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";
或者
$SQLquery = "SELECT * FROM albums WHERE price2 > 1 ORDER BY ((price-price2)/price) ASC";
你应该试试:
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
Order By 根据指定的列工作。您可以从包含基于该公式的值的新列的基表创建视图或临时表,然后对该列进行排序。