다음 테이블 정의와 데이터를 사용해서 각 고객의 총 지불액과 함께 고객 이름을 반환하는 쿼
리를 작성하세요. 해당 고객에 대한 지불 기록이 없는 경우에도 모든 고객을 포함합니다.
Customer:
Customer_id Name
----------- ---------------
1 John Smith
2 Kathy Jones
3 Greg Oliver
Payment:
Payment_id Customer_id Amount
---------- ----------- --------
101 1 8.99
102 3 4.99
103 1 7.99
mysql> SELECT c.name, sum(p.amount)
-> FROM customer c LEFT OUTER JOIN payment p
-> ON c.customer_id = p.customer_id
-> GROUP BY c.name;
+-------------+---------------+ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.