본문 바로가기
Coding/데이터베이스

[오라클] 마당서점

by 찡콩찡 2022. 8. 29.
--1.도서번호가 1번인 도서의 이름
select bookname 
from book 
where bookid='1';

--2. 가격이 20,000원 이상인 도서의 이름
select bookname 
from book 
where price>=20000;

--3.박지성의 총 구매액(박지성의 고객번호는 1번으로 놓고 작성)
select name,sum(saleprice)
from orders natural join customer
where name='박지성' group by name;

--4.박지성이 구매한 도서의 수(박지성의 고객번호는 1번으로 놓고 작성)
select name,count(*) 
from orders natural join customer
where name='박지성' group by name;

--2.1 마당서점의 도서의 총개수
select count(*) from book;

--2.2 마당서점에 도서를 출고하는 출판사의 총 개수
selec count(distinct publisher) from book;

--2.3 모든 고객의 이름, 주소
select name,address
from customer;

--2.4 2014년 7월 4일~ 7월 7일 사이에 주문 받은 도서의 주문 번호(to_date/to_charactor)
select orderid 
from orders
where orderdate between
to_date('2014-07-01','YYYY-MM-DD') and to_date('2014-07-07','YYYY-MM-DD');

--2.5 2014년 7월 4일 ~ 7월 7일 사이에 주문 받은 도서를 제외한 도서의 주문번호
select orderid 
from orders
where not orderdate between
to_date('2014-07-01','YYYY-MM-DD') and to_date('2014-07-07','YYYY-MM-DD');

--2.6 성이 '김'씨인 고객의 이름과 주소
select name,address
from customer
where name like '김%';

--2.7 성이 '김'씨이고 이름이 '이'로 끝나는 고객의 이름과 주소
select name,address
from customer
where name like '김%아';

--출판사별 판매액 합계, 판매 도서수, 판매액 평균
select publisher,sum(price),count(*),avg(price)
from book group by publisher; 

--주문일자별 판매권수
select orderdate, count(*)
from orders 
group by orderdate; 

--도서별 판매액 합계, 판매 도서수를 도서명과 출판사와 함께 출력
select bookname,publisher,sum(price),count(*)
from book b natural join orders o
group by bookname, publisher;

'Coding > 데이터베이스' 카테고리의 다른 글

PL/ SQL 구조  (1) 2022.09.19
[오라클] 마당서점 복습하기2 : 조인함수,서브쿼리사용  (0) 2022.09.05
[오라클] SQL기초 복습예제  (0) 2022.08.22
프로시저  (0) 2022.07.04
DB 놀이2  (0) 2022.06.20