두 테이블의 교집합을 찾는 JOIN
모든 'customer'의 'payment' amount,payment_date를 확인하기
SELECT
C.customer_id ,C.first_name
,C.last_name ,C.email
,P.amount ,P.payment_date
FROM customer c
INNER JOIN payment p
ON C.customer_id =P.customer_id ;
그 중 id=3인 사람의 내역 확인하기
SELECT
c.customer_id ,c.first_name
,c.last_name , c.email
,p.amount ,p.payment_date
FROM customer c
INNER JOIN payment p
ON c.customer_id = p.customer_id
WHERE c.customer_id = 3 ;
고객의 payment data에 담당한 staff 이름도 같이 표시하기
SELECT
c.customer_id ,c.first_name
,c.last_name ,c.email
,p.amount ,p.payment_date
,s.first_name AS S_first_name
,s.last_name AS S_last_name
FROM customer c
INNER JOIN payment p
ON c.customer_id = p.customer_id
INNER JOIN staff s
ON p.staff_id = s.staff_id ;
'데이터 분석 > SQL' 카테고리의 다른 글
[SQL 문법] FULL OUTER JOIN (0) | 2020.11.03 |
---|---|
[SQL 문법] SELF JOIN + ON (0) | 2020.11.03 |
[SQL 문법] IS NULL (0) | 2020.10.31 |
[SQL 문법] LIKE (0) | 2020.10.31 |
[SQL 문법] BETWEEN (0) | 2020.10.31 |