728x90
반응형
- group by : 동일한 값을 갖는 필드를 묶는 기능 (리스트업/카운트/통계)
아래 데이터에서 from -> group by -> select 순으로 구해짐실행되는 순서 꼭 알아둘 것
select name, count(*) from users group by name; select count(*) from users where name = "남**";
o 주차별 학습목표 개수 구하기
select week, count(*) from checkins group by week;
- 최대/최소/평균/합계 구하기
select week, max(likes) from checkins group by week; select week, min(likes) from checkins group by week; select week, avg(likes) from checkins group by week; select week, sum(likes) from checkinsgroup by week;
- order by : ㄱ->ㅎ 순 정렬
SELECT payment_method, count(*) from orders where course_title = "전과목 종합반" group by payment_method order by count(*) desc; //desc = 내림차순
- as : 복잡한 쿼리문일 때 유용
select * from orders as o where o.course_title ="전과목 종합반" select name as 이름, count(*) as 인원 from users group by name;
728x90
반응형
'IT 강의' 카테고리의 다른 글
SQL 강의 핵심요약 #5. as/join/alias/desc (0) | 2021.05.05 |
---|---|
SQL 강의 핵심요약 #4. SQL 쿼리 작성 꿀팁 (0) | 2021.05.05 |
SQL 강의 핵심요약 #2. limit/distinct/count/distinct (0) | 2021.05.05 |
SQL 강의 핵심요약 #1. where/between/in/like (0) | 2021.05.05 |
코린이 필수꿀팁 #7. Ajax (데이터 요청하고 응답받기) (0) | 2021.05.05 |