Notice
Recent Posts
Recent Comments
Link
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

290570

06.11 본문

java_spring (2024.05 ~ 2024.10)

06.11

qordpsem 2024. 6. 11. 15:04

#날짜관련 클래스

Date

Calendar 

GregorianCalendar  ( Calendar 후손 / 윤년 정보 추가)

 

Date  = >    0이 Sunday

Calendar  = >    1이 Sunday

 

 

 

#집계함수   >>  결과 1건 (일반속성 사용불가)

레코드를 조회할때 레코드의 수, 합, 평균 등 구할때 사용하는 함수

레코드 수  :   count (칼럼이름)

총합  :   sum (칼럼이름)

평균  :   avg (칼럼이름)

최고  :   max (칼럼이름)

최저  :   min (칼럼이름)

 

 

 

ex) 모든 도서 가격 총합 출력

select sum(price) from book;

ex) 도서의 최고 가격 조회

select max(price) from book;

ex) 모든 도서 수 조회

select count(price) from book;

select count(bookname) from book;      <<     count(컬럼이름)  :  컬럼 값이 null이 아닌 레코드 수

select count(*) from book;       <<       count(*)  :  모든 레코드의 수

 

 

 

 

 

 

ex) '홍길동' 고객이 주문한 총 건수와 총 주문금액 출력

select sum(saleprice), count(*) from customer c, orders o where c.custid = o. custid and name = '홍길동';

 

select sum(saleprice) sum , count(*) cnt

from customer c, orders o

where c.custid = o.custid and

name = '홍길동';

 

ex) '침입' 관련 도서의 총 도서 수와 평균가격, 최고가격, 최저가격 출력

select count(*) cnt, avg(price) avg, max(price) max, min(price) min from book where bookname like  '%침입%';

 

ex) '개발1팀' 에 근무하는 총 직원 수와 평균 급여 출력

select count(*) cnt, avg(salary) avg

from emp e, dept d

where e.dno = d.dno and

dname = '개발1팀';

 

ex) '2024/06/01'과 '2024/06/10' 사이에 주문한 건수와 총 주문금액 출력

select count(*) cnt, sum(saleprice) sum

from orders

where orderdate between '2024/06/01' and '2024/06/10';

 

ex) 개발팀의 근무 직원들 총 급여를 출력

select sum(salary) sum

from emp e, dept d

where e.dno = d.dno and

dname like '%개발%';

 

 

 

 

 

 

select price from book;   -  12개 행

select bookname, price from book;   -  12개 행

select sum(price) from book;    -   1개 행

 

select bookname, sum(price) from book;  => 불가능

ORA-00937: 단일 그룹의 그룹 함수 아니라고 오류 나옴

 

 

 

 

#group by 사용

모든 도서의 평균금액은 한건으로 나옴

만약, 출판사 별 평균 금액을 알고싶다면 ?   =>  group by 사용

 

 

select avg(price) from book;   -   1건

 

 

 

select avg(price) from book group by publisher;   -   출판사 개수 만큼

 

 

출판사 명까지 나오게 하려면

 

 

 

select publisher, avg(price) from book group by publisher;

'java_spring (2024.05 ~ 2024.10)' 카테고리의 다른 글

06.12  (0) 2024.06.12
24.06.12  (0) 2024.06.12
24.06.11  (0) 2024.06.11
오답노트  (0) 2024.06.10
24.06.07  (0) 2024.06.07