简体   繁体   English

我正在使用3表联接计算每个客户在mysql上花费的总金额

[英]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.

相关问题 SQL连接表,所有客户花费的总额 - SQL join tables, total spent by all customers 显示每个客户每月平均花费的枢轴查询 - Pivot query that shows the average amount spent per customer for each month Output 客户花费的总金额以及他/她花费最多的项目 - Output the total amount spent by the customer and the item on which he/she spent the most 如何使用 mysql 显示特定项目在特定日期花费的总金额 - How to display total amount spent on a particular day for a particular item using mysql 计算特定月份mysql的平均支出(支出/人) - Calculating average spending (amount spent/person) in a particular month mysql 我怎样才能获得在特定项目上花费的总金额? - How could I get the total amount spent on a particular item? 在 MYSQL 中使用内部联接时获取总量的问题 - Issue to get total amount while using inner join in MYSQL 使用 JOIN 和订单花费金额的 sum () 查询以获取客户列表 - query to get customer list using JOIN with sum () of the amounts spent in orders 每个顾客在餐厅消费的总金额是多少? 无法看到不同的 customer_id .. 仅显示所有金额的一个相同 id - What is the total amount each customer spent at the restaurant? Not able to see different customer_id.. shows only one same id for all amounts 在MySQL中获取每月总费用 - get total amount of expenses per month in MySQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM