将两个列值从mysql中的不同表中相乘

时间:2014-02-22 07:43:56

标签: php mysql database

我有2个表客户和牛奶,如下所示

客户

customers (cid, name,  price);

milk (mid, customer_id, milk_letters, mprice)

我想在[{1}}

中加倍价格和milk_letters以及store

我正在尝试

mprice where customer_id = cid

1 个答案:

答案 0 :(得分:1)

您可以在一个查询而不是2

中执行此操作
INSERT INTO milk (customer_id, milk_letters, milk_date, mprice)
SELECT {$cid}, {$milk_letters}, NOW(), customers.price * {$milk_letters}
FROM customers
WHERE customers.cid = {$cid}