0
我有一个产品price
2列表示正常价格和new_price
代表产品的报价。当我按价格订购时,如果两列都填满了,我无法得到正确的订单。现在它先以新价格然后按价格订购。我想以某种方式连接价格。Mysql通过2列表示价格和新价格
if($order==1)
{
$order_by='Produse.New_price ASC,Produse.Price ASC';
}
if($order==2)
{
$order_by='Produse.New_Price DESC,Produse.Price DESC';
}
if($order==3)
{
$order_by='Produse.Nume_Prod ASC';
}
if($order==4)
{
$order_by='Produse.Nume_Prod DESC';
}
if($order==0)
{
$order_by='Produse.Nume_Prod DESC';
}
$stmt=$dbh->prepare("Select * FROM Produse
INNER JOIN Categorii on Produse.ID_Categorie=Categorii.ID_Categorie
where Categorii.Nume_Categ=:id
ORDER BY $order_by");
$stmt->bindParam(':id',$id,PDO::PARAM_INT);
$stmt->execute();
使用COALESCE返回在新的价格的第一个非空价格vs price ...'通过合并订购('Produse.new_price,produse.price)'这个假设当两者都存在时,您想以新价格订购。并且新价格为空,您只需按价格订购。 – xQbert
取决于你想要的东西......'order by new_price + price DESC'' by order by IF(new_price IS NOT NULL,new_price,price)DESC'或者简单地按一列排序,因为对我来说它根本没有意义;) – iRaS
“以某种方式连接价格”是什么意思? –