我有4张桌子:
customer(customer_id,last_name,first_name)
产品(isbn,书名,ListPrice)
order_has_products(customer_id,order_id,isbn)
订单(order_id,customer_id)
我想计算每位顾客在书上花费的总金额。在我看来,我将加入3张桌子。我需要一个"数量"列能够做到这一点吗?
答案 0 :(得分:0)
SELECT SUM(products.ListPrice) FROM order_has_products
INNER JOIN products on order_has_products.isbn = products.isbn
GROUP BY order_has_products.customer_id