Mysql 如何选择指定其他两个字段值的两个不同表字段的乘积之和?

Mysql 如何选择指定其他两个字段值的两个不同表字段的乘积之和?,mysql,Mysql,基于此表架构: products +----+------+-------+--------+--------------+-------+-------+------+-------+ | Id | Name | Price | Detail | Product_type | Image | Color | Size | Stock | +----+------+-------+--------+--------------+-------+-------+------+-------+

基于此表架构:

products

+----+------+-------+--------+--------------+-------+-------+------+-------+
| Id | Name | Price | Detail | Product_type | Image | Color | Size | Stock |
+----+------+-------+--------+--------------+-------+-------+------+-------+

order_details

+----+------------+--------+------+-------+----------+
| Id | Product_id | Amount | Size | Color | Order_id |
+----+------------+--------+------+-------+----------+

orders

+----+-----------+------------+----------+
| Id | Client_id | Date_start | Date_end |
+----+-----------+------------+----------+
如何选择指定客户和订单id的
products.Price*order\u details.Amount的
SUM()
(如果此函数是必需的话)

我尝试过这个查询,其中包括:

SELECT SUM((SELECT pr.Price FROM products pr WHERE pr.Id = od.Product_id) * od.Amount) AS Total 
FROM order_details od
WHERE (SELECT o.Client_id FROM orders o WHERE o.Id = $order) = $client
但是它返回了一个错误的结果,我不知道怎么做。另外请注意,我想使用子查询


谢谢。

请勿使用子选择,请使用连接:

SELECT orders.Id, SUM(products.Price * order_details.amount)
FROM orders
LEFT JOIN orders_details ON orders.Id = order_details.Order_id
LEFT JOIN products ON products.Id = order_details.Product_id
GROUP By orders.Clien_id, orders_details.Product_id

感谢您的回复,但这将返回一组两行,其中第二行是这样的:
Id=1 | Total=NULL
。我如何在这个查询中指定订单id和客户机?对不起,我是新来的。