gpt4 book ai didi

php - 按价格和折扣价格排序

转载 作者:可可西里 更新时间:2023-11-01 08:40:39 24 4
gpt4 key购买 nike

我有下表:

product_id | price | discountPrice
1 | 15 | 12
2 | 13 | 0
3 | 20 | 6

我想按折扣价对结果进行排序,但如果某些 product_id 的 discountPrice 等于 0,则此 product_id 应按价格排序。

预期结果:

product_id | price | discountPrice
3 | 20 | 6
1 | 15 | 12
2 | 13 | 0

最佳答案

I want to sort result by discount Price, but if some product_id have a discountPrice equal to 0, this product_id should be sort by price.

SELECT * FROM `table` ORDER BY CASE WHEN `discountPrice` = 0 THEN `price` ELSE `discountprice` END DESC

关于php - 按价格和折扣价格排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33667591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com