How to order a MySQL query by range?

Chris

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?

Pinoniq

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]

編集
0

コメントを追加

0

関連記事

分類Dev

MySQL "Order By" query

分類Dev

Does MySQL execute a query in the order it is written?

分類Dev

MySQL query with less than and ORDER BY DESC

分類Dev

MySQL query with multiple random values but sum always within a range

分類Dev

Django Query: How to order posts by amount of upvotes?

分類Dev

How to implement "order by" together with "group by" in query

分類Dev

MySQL query order items based on next and previous item

分類Dev

how to convert mysql query to zend query?

分類Dev

How to check performance of mysql query?

分類Dev

How to combine "LIKE" with "IN" in a MYSQL query?

分類Dev

How to pass & symbol in MySQL query?

分類Dev

php order by custom range

分類Dev

How can I order this MySQL Date?

分類Dev

How to ORDER BY within LEFT JOIN in MySQL 5.7

分類Dev

How to sort DynamoDB query result without specifying range key value

分類Dev

Mongoengine query with date range

分類Dev

Cassandra Inconsistent Range Query

分類Dev

How to order 2 related tables in one query having order fields both of them

分類Dev

MySQL query to search in between two time range between two dates using timestamp data

分類Dev

how to improve mysql query speedy with indexes?

分類Dev

How to get database structure in MySQL via query

分類Dev

How to get a mysql query to use a specific index?

分類Dev

How to do multiple counts in a MYSQL select query?

分類Dev

How to display zero values in mysql query?

分類Dev

How to escape a period in mySql JSON query

分類Dev

How to do this query against MySQL database table?

分類Dev

How to use common parameter for Mysql PDO query

分類Dev

Mysql: How to query with if else condition inside if

分類Dev

How to write a calculation query in MySQL with 2 tables?

Related 関連記事

  1. 1

    MySQL "Order By" query

  2. 2

    Does MySQL execute a query in the order it is written?

  3. 3

    MySQL query with less than and ORDER BY DESC

  4. 4

    MySQL query with multiple random values but sum always within a range

  5. 5

    Django Query: How to order posts by amount of upvotes?

  6. 6

    How to implement "order by" together with "group by" in query

  7. 7

    MySQL query order items based on next and previous item

  8. 8

    how to convert mysql query to zend query?

  9. 9

    How to check performance of mysql query?

  10. 10

    How to combine "LIKE" with "IN" in a MYSQL query?

  11. 11

    How to pass & symbol in MySQL query?

  12. 12

    php order by custom range

  13. 13

    How can I order this MySQL Date?

  14. 14

    How to ORDER BY within LEFT JOIN in MySQL 5.7

  15. 15

    How to sort DynamoDB query result without specifying range key value

  16. 16

    Mongoengine query with date range

  17. 17

    Cassandra Inconsistent Range Query

  18. 18

    How to order 2 related tables in one query having order fields both of them

  19. 19

    MySQL query to search in between two time range between two dates using timestamp data

  20. 20

    how to improve mysql query speedy with indexes?

  21. 21

    How to get database structure in MySQL via query

  22. 22

    How to get a mysql query to use a specific index?

  23. 23

    How to do multiple counts in a MYSQL select query?

  24. 24

    How to display zero values in mysql query?

  25. 25

    How to escape a period in mySql JSON query

  26. 26

    How to do this query against MySQL database table?

  27. 27

    How to use common parameter for Mysql PDO query

  28. 28

    Mysql: How to query with if else condition inside if

  29. 29

    How to write a calculation query in MySQL with 2 tables?

ホットタグ

アーカイブ