👉 데이터 분석의 목적: 쌓여있는 날것의 데이터 → 의미를 갖는 '정보'로의 변환
👉 더 나아가면? '범주 (category)' 각각의 정보가 궁금할 수 있습니다
👉 우선 과목별 신청자수를 구한다고 생각해봅시다! 자, 지금까지 배운 내용을 사용해볼까요?
select count(*) from orders
where course_title = "웹개발 종합반";
👉 이번에는 성씨별 회원수를 구하고 싶어요! 과목별 신청자수 구했던것처럼 하면 될까요?
앗, 그런데 스파르타 회원의 성씨가 총 몇개였죠?
👉 이렇게 불필요한 반복작업을 하도록 프로그래머들이 가만두지 않았겠죠?
그래서 SQL에는 Group by라는 문법이 있습니다.
👉 Group by란?
동일한 범주를 갖는 데이터를 하나로 묶어서, 범주별 통계를 내주는 것을 의미해요.
Group by를 이용하면 1) 같은 성씨의 데이터를 하나로 묶고 2) 각 성씨의 회원수를 구할 수 있어요.
select name, count(*) from users
group by name;
select * from users
order by email;
select * from users
order by name;
select * from users
order by created_at desc;
select payment_method, count(*) from orders
where course_title = "앱개발 종합반"
group by payment_method;
select name, count(*) from users
where email like '%gmail.com'
group by name;
select * from orders o
where o.course_title = '앱개발 종합반'
select payment_method, count(*) as cnt from orders o
where o.course_title = '앱개발 종합반'
group by payment_method
where email like '%naver.com' and course_title = '앱개발 종합반'
group by payment_method
select payment_method, count(*) from orders
select payment_method, count(*) from orders
where email like '%naver.com' and course_title = '앱개발 종합반'
group by payment_method