开发者

Using 2 fields in ORDER BY clause

开发者 https://www.devze.com 2023-01-14 10:04 出处:网络
I have a page that show \"special offers\", and i need to orde开发者_如何学编程r the results by discount value. Besides i want that products with quantity=0 are shown at the end of the list (regardles

I have a page that show "special offers", and i need to orde开发者_如何学编程r the results by discount value. Besides i want that products with quantity=0 are shown at the end of the list (regardless of the discount value).

So, there is any way to do that using only SQL? I mean... if i set "ORDER BY discount, quantity DESC" the list show products ordered by discount, and each groups of discout is ordered by the quantity value... this isn't what i want.

Thanks in advance...


ORDER BY CASE Quantity WHEN 0 THEN 99999999 ELSE Discount END, Quantity DESC


SELECT * FROM `products` ORDER BY discount WHERE quantity > 0
UNION SELECT * FROM `products` WHERE quantity <= 0;

Like this?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号