Is there a pure MySQL way of ordering elements by range? So let´s say I have table "products" with two columns for prices, one is the old price, one the new one. I now want to select all products and order them by the range of the previous price and the current price. So actually something like ORDER BY (previous_price - current_price)
. Is there any way to do that or do I need to use a programming language to reorder the array?
Exactly as you propose. But then the SQL way:
You select a field called price
_range that equals previous_price - current_price
:
SELECT (previous_price-current_price) as price_range
And then you order it:
ORDER BY price_range
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加