mysql order by numeric difference
1/10/2008Whilst recently implementing a discount system for an e-commerce site I needed to apply the biggest discount should there be a product which was eligible for more than one discount. As the system allowd x for y type discounts I needed to order my results with x-y so I could find out which of the x for y discounts was the best value for money.
In order to do this I used something like the following SQL:
SELECT discount FROM discounts WHERE ABS(x_value - y_value) DESC
With thanks to:
http://www.bradino.com/mysql/order-by-numeric-difference/
No comments yet.