如何使用MySQL获得依赖于id的价格
我将如何使用MySQL获得依赖于id的价格,mysql,sql,Mysql,Sql,我将价格与数量之和相乘,得到总数。问题是,当我将不同表中的两列相乘时,我得到了错误的结果。价格与sup\u-med\u-id不匹配,它只取了第一行10。我如何获得价格取决于sup\u med\u id sup_med_id price sup_id rec_order_dtls sup_med_id rec_quantity 1 10.00 2 1 1 200 2
价格
与数量之和相乘,得到总数。问题是,当我将不同表中的两列相乘时,我得到了错误的结果。价格与sup\u-med\u-id
不匹配,它只取了第一行10
。我如何获得价格取决于sup\u med\u id
sup_med_id price sup_id rec_order_dtls sup_med_id rec_quantity
1 10.00 2 1 1 200
2 12.00 2 2 2 100
date_id date
1 2019-01-01
2 2019-01-02
... ...
输出
Month Quantity Total Supplier
...
Jul 0 0 NULL
Aug 300 3000 Unilever
我没有把所有的数据和表格都放在上面。
我希望这就是下面的结果
预期产量
Month Quantity Total Supplier
...
Jul 0 0 NULL
Aug 300 3200 Unilever
您好,如果我正确理解了您的问题,那么您需要将数量和价格相乘才能得到总数。
如果正确,则可以使用以下查询:
select tt.rec_quantity as quantity, (price * rec_quantity) as total from temp t inner join temp2 tt on t.sup_med_id=tt.sup_med_id;
如果其中一个表没有匹配数据,则可以使用左联接。
如果需要帮助,请告诉我。请原谅我的错误。我已经更新了我的问题。我想乘以价格取决于供应商id和数量的总和。。。
select tt.rec_quantity as quantity, (price * rec_quantity) as total from temp t inner join temp2 tt on t.sup_med_id=tt.sup_med_id;