我有2个表顾客和牛奶,如下所示
客户
customers (cid, name, price, total);
乳
milk (mid, customer_id, milk_letters, mprice)
我正在尝试
$cid = $_POST['cid'];
我想将客户表更新为牛奶的总和(mprice),其中customer_id = cid
答案 0 :(得分:0)
sql代码:
UPDATE customers c
SET total=(SELECT SUM(mprice) FROM milk WHERE customer_id=c.cid)
WHERE c.cid=$cid
也使用intval
$cid = intval($_POST['cid']);