Php Mysql-按两个价格列作为一列订购
我有这样一个产品表:Php Mysql-按两个价格列作为一列订购,php,mysql,sorting,sql-order-by,Php,Mysql,Sorting,Sql Order By,我有这样一个产品表: id | name | price |discount| discount_price 1 | Product 1| 100 | 0 | 2 | Product 2| 150 | 1 | 75 3 | Product 3| 200 | 1 | 80 我想做一个按价格递增的过滤器。但是当我想按价格排序时,我只能做一列 没有折扣价格列,就没有正确的订单 我需要得到这样的结果(价格上涨):
id | name | price |discount| discount_price
1 | Product 1| 100 | 0 |
2 | Product 2| 150 | 1 | 75
3 | Product 3| 200 | 1 | 80
我想做一个按价格递增的过滤器。但是当我想按价格排序时,我只能做一列
没有折扣价格列,就没有正确的订单
我需要得到这样的结果(价格上涨):
这就行了
select
id,
name,
price,
discount,
discount_price
from
table
order by
(case
when discount_price = '' then CAST(price as INT)
else CAST(discount_price as INT)
end);
看见
select
id,
name,
price,
discount,
discount_price
from
table
order by
(case
when discount_price = '' then CAST(price as INT)
else CAST(discount_price as INT)
end);