[英]I am calculating total amount spent per customer in mysql, using join with 3 tables
I have 4 tables: 我有4张桌子:
customer (customer_id, last_name, first_name) 客户(customer_id,last_name,first_name)
products (isbn, book title, ListPrice) 产品(isbn,书名,标价)
order_has_products (customer_id, order_id, isbn) order_has_products(customer_id,order_id,isbn)
orders (order_id, customer_id) 订单(order_id,customer_id)
I want to calculate the total amount spent on books per customer.It seems to me I will be joining 3 tables.Do i need a "quantity" column to be able to do this? 我想计算每个客户在书本上花费的总金额。在我看来,我将加入3张桌子。我是否需要“数量”列才能做到这一点?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.