mysql_query("UPDATE productlist
SET pleft=pleft+(SELECT SUM(qty) FROM sales
WHERE (sales.name = productlist.pdesc)
AND (sales.name1 = productlist.pdesc1))");
答案 0 :(得分:0)
您想使用带有第一个非空值的COALESCE
:
SELECT SUM(COALESCE(qty, 0)) ...
答案 1 :(得分:0)
您可以使用IFNULL功能:
mysql_query("UPDATE productlist SET pleft=pleft + IFNULL( (SELECT SUM(qty) FROM sales WHERE (sales.name = productlist.pdesc) AND (sales.name1 = productlist.pdesc1), 0)");
此外,如果qty字段可以为NULL,则最好具有:
mysql_query("UPDATE productlist SET pleft=pleft + IFNULL( (SELECT SUM(IFNULL(qty,0)) FROM sales WHERE (sales.name = productlist.pdesc) AND (sales.name1 = productlist.pdesc1), 0)");