728x90
반응형
select * from product;
select distinct type from product;--타입을 중복제거해서 출력(추가계산이 불가능)
select type from product group by type;--타입별로 묶어서 타입명을 출력(추가계산이 가능)
select type, count(*) from product group by type;--타입별 개수
select type, sum(price) from product group by type;--타입별 합계
select type, count(*) from product group by type order by count(*) desc;--타입별 개수를 많은 순서로 정렬
select type, count(*) "개수" from product group by type order by "개수" desc;--타입별 개수를 많은 순서로 정렬
select type, sum(price) from product group by type order by sum(price) desc;--타입별 합계를 큰순서부터 정렬
select type, sum(price) "합계" from product group by type order by "합계" desc;--타입별 합계를 큰순서부터 정렬
select type, max(made) from product group by type;
select type, max(made) "제조일자" from product group by type order by "제조일자" desc;
#Group query
-그룹별로 데이터를 조회할 필요가 잇을경우
ex) 개수 / 합계 / 평균 / 최대 / 최소 와 같은 작업을할떄 사용
-집계함수들을 이용하여 그룹별로 구분하여 정보를 획득하는 것이 목표
-어떤 조건으로 그룹을 지을 것인지 명시해야한다
group by 항목 [having 항목조건]
'[DBMS] > - Oracle' 카테고리의 다른 글
[Oracle]집합연산 (0) | 2022.05.30 |
---|---|
[Oracle]기본키 Primary key (0) | 2022.05.30 |
[Oracle]TopN Queey 탑N쿼리 (0) | 2022.05.30 |
[Oracle]정렬 (Sort) asc/desc (0) | 2022.05.30 |
[Oracle]서브쿼리(subQuery) (0) | 2022.05.30 |
댓글