Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysql-按两个价格列作为一列订购_Php_Mysql_Sorting_Sql Order By - Fatal编程技术网

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);