성씨별로 몇 명의 회원이 있는지 알아보자
select name, count(*) from users group by name;
위 쿼리가 실행되는 순서: from → group by → select
1. from users: users 테이블 데이터 전체를 가져옵니다. 예) 이**, 이**, 김**, 김**, 박** 이렇게 데이터가 있었다면, 이**는 2개, 김**은 2개, 박**은 1개!
뭔가 찝찝했던 성씨별 회원수 데이터
85, 14, 11, 16, 21, 6, 6.. 뭔가 정렬해주고 싶다면?
select name, count(*) from users group by name order by count(*);
* 내림차순으로 알아보고자 한다면 마지막에 desc를 붙인다.
select name, count(*) from users group by name order by count(*) desc;
👉 위 쿼리가 실행되는 순서: from → where → group by → selectselect payment_method, count(*) from orders where course_title = "웹개발 종합반" group by payment_method;
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
- 숙제: 네이버 이메일을 사용하여 앱개발 종합반을 신청한 주문의 결제수단별 주문건수 세어보기
SELECT payment_method, count(*) as ant FROM orders
where email like '%naver.com' and course_title = '앱개발 종합반'
GROUP by payment_method