Professional Documents
Culture Documents
4주 데이터베이스응용 0328
4주 데이터베이스응용 0328
create table customer( custid number(2) primary key, name varchar(30), address
varchar2(30), phone varchar2(20) );
create table orders( orderid number(2) primary key, custid number(2) references
customer(custid), bookid number(2) references book(bookid), saleprice number(8),
orderdate date);
12. customer 테이블에서 고객번호가 '5'인 고객의 주소를 '대한민국 부산'으로 변경하시오.
update customer set address = '대한민국 부산' where custid = 5;
15. update customer set address = '대한민국 서울'; //모든 레코드의 주소가 한번에 '대한민국
서울'로 변경된다.
19. delete from customer; //where 이 없으면 customer 테이블의 모든 레코드가 삭제된다.
25. 가격이 8000 원 이상인 도서를 구매한 고객에 대하여 고객별 주문 도서의 총수량을 구하시오. 단 2 권 이상
구매한 고객만 구하시오.
과제
30. 가장 비싼 도서의 이름을 보이시오.
select bookname from book where price=(select max(price) from book);
31. 가장 값싼 도서의 이름을 보이시오.
select bookname from book where price=(select min(price) from book);
32. '대한미디어'에서 출판한 도서를 구매한 고객의 이름을 보이시오.
select name from customer where custid in(select custid from orders where bookid
in(select bookid from book where publisher
= '대한미디어'));
34. book 테이블에 새로운 도서 '스포츠 의학'을 삽입하시오. 단 출판사명은 '한솔의학서적'이고, 가격은
90000 원
insert into book values(11, '스포츠 의학', '한솔의학서적', 90000);
35. book 테이블에 새로운 도서 'C 언어 프로그래밍'을 삽입하시오. 단 출판사명은 '글로벌'이고, 가격은
24000 원
insert into book values(12, 'C 언어 프로그래밍', '글로벌', 24000);
37. customer 테이블에서 박세리 고객의 주소를 김연아 고객의 주소로 변경하시오.
update customer set address = (select address from customer where name = '김연아')
where name = '박세리';
47. 이름, 전화번호가 포함된 고객목록을 보이시오. 단 전화번호가 없는 고객은 '연락처없음'으로 표시하시오.
select name as 이름, NVL(phone, '연락처없음') as 전화번호 from customer;
48. 이름, 전화번호가 포함된 고객목록을 보이시오. 단 전화번호가 없는 고객인 '연락처미기재'으로 표시하시오.
50. 주소에 '대한민국'을 포함하는 고객들로 구성된 뷰를 만들고 조회하시오. 뷰의 이름은 vw_customer 로
설정
create view vw_customer as select * from customer where address like '%대한민국%';
select * from vw_customer;