表格交易:business_key = customer_id
customer_id|product_type|amount ------------------------------- cus1 | shoes | 100 cus1 | shoes | 50 cus1 | clothes | 100 cus2 | clothes | 500 cus2 |clothes | 21
table transactionsbycustomer:business_key = customer_id + product_type
customer_id|product_type|amount ------------------------------- cus1 |shoes |150 cus1 |clothes | 50 cus2 |clothes |521
我需要通过客户'在' Transactions中获得金额的值。使用SQL的表?请帮忙!
答案 0 :(得分:0)
这是非常基本的SQL。
SELECT customer_id, product_id, sum(amount) as total
FROM transactionsbycustomers
GROUP BY customer_id, product_id