如何使用CASE WHEN在MySQL和PDO中运行更新查询.
以下查询将CASE列更新为0.
$query= "Update payments SET
total = :total,paid = CASE
WHEN paid > :new THEN paid = :new
ELSE paid
END,due = CASE
WHEN paid < :new THEN due = :new - paid
ELSE due
END
WHERE id = :id ";
$update= $db->prepare($query);
$update->bindparam(':total',$new);
$update->bindparam(':new',$new);
$update->bindparam(':id',$id);
$update->execute();
最佳答案
原文链接:https://www.f2er.com/mysql/531937.html