2014-07-08 16 views
-4

테이블 트랜잭션 : business_key = CUSTOMER_IDSQL : 입력에 따라 값을 도출

 
customer_id|product_type|amount 
------------------------------- 
cus1  | shoes  | 100 
cus1  | shoes  | 50 
cus1  | clothes | 100 
cus2  | clothes | 500 
cus2  |clothes  | 21 

테이블 transactionsbycustomer : business_key = CUSTOMER_ID + 제품 _ I가 transactionsbycustomer '에 값을 도출해야

 
customer_id|product_type|amount 
------------------------------- 
cus1  |shoes  |150 
cus1  |clothes  | 50 
cus2  |clothes  |521 

'SQL을 사용하는 테이블? 도와주세요!

+0

다음과 같은 의미가 있습니다. 'SELECT amount FROM transactionsbycustomer WHERE customer_id = "cus1"';; 무엇이 특별히 필요한가요? – JiFus

+0

샘플 데이터를 기반으로 예상 출력의 예를 추가하십시오. –

+0

당신은'GROUP BY' 절을 생각하고 있습니다. – mustaccio

답변

0

이것은 매우 기본적인 SQL입니다.

SELECT customer_id, product_id, sum(amount) as total 
FROM transactionsbycustomers 
GROUP BY customer_id, product_id 
관련 문제