데이터분석 6기/사전캠프
[TIL]데이터분석 사전캠프 10일차 - Lv4. 단골 고객님 찾기
seyeon1130
2025. 2. 7. 17:36
엑셀 데이터 DBeaver에 연결하는 방법
DBeaver에 연결해서 연습하고 싶다면? | Notion
MySQL 로컬 이용해서 DBeaver에 CSV 파일을 연결한 뒤에 쿼리를 직접 쳐봅시다!
teamsparta.notion.site
엑셀 데이터를 dbeaver에 연결해서 연습하는 방법
Lv4. 단골 고객님 찾기
테이블
문제 1번
1번 코드
select c.CustomerName ,count(1) OrderCount, sum(o.TotalAmount ) TotalSpent
from customers c right join orders o on c.CustomerID = o.CustomerID
group by 1;
결과화면
문제 2번
2번 코드
select Country, CustomerName Top_Customer, max(TotalSpent) Top_Spent
from(
select c.Country, c.CustomerName, sum(o.TotalAmount) TotalSpent,
rank() over (partition by c.Country order by sum(o.TotalAmount) desc) ranking
from customers c
right join orders o on c.CustomerID = o.CustomerID
group by c.Country, c.CustomerName
)a
where ranking=1
group by 1,2
order by 3 desc;
결과화면
알게된 점
- 집계함수는 중첩이 안된다. max(sum~) 안됨
- 모든 비집계함수는 group by 절에 포함해야함.