포스트

프레임워크 SQL 1일차

프레임워크 SQL 1일차

Q1

Q1-1 : 도서번호가 1인 도서의 이름

Image Source Code

1
select bookname from book where bookid like 1;

출력 결과

bookname
축구의 역사

Q1-2 : 가격이 20,000원 이상인 도서의 이름

Image Source Code

1
select bookname from book where price >= 20000;

출력 결과

bookname
축구의 이해
골프 바이블
야구의 추억

Q1-3 : 박지성의 총 구매액

Image Source Code

1
select custid, sum(saleprice) as 총구매액 from orders where price custid like 1;

출력 결과

custid총구매액
139000

Q1-4 : 박지성이 구매한 도서의 수

Image Source Code

1
select custid, count(orderdate) as 총구매량 from orders where custid like 1;

출력 결과

custid총구매량
13

Q2

Q2-1 : 마당서점 도서의 총개수

Image Source Code

1
select count(*) as 마당서점도서총갯수 from book;

출력 결과

마당서점도서총갯수
10

Q2-2 : 마당서점에 도서를 출고하는 출판사의 총개수

Image Source Code

1
select count(distinct publisher) as 마당서점출판사총갯수 from book;

출력 결과

마당서점출판사총갯수
6

Q2-3 : 모든 고객의 이름, 주소

Image Source Code

1
select name as 고객, address as 주소 from customer;

출력 결과

고객주소
박지성영국 맨체스타
김연아대한민국 서울
김연경대한민국 경기도
추신수미국 클리블랜드
박세리대한민국 대전

Q2-4 : 2024년 7월 4일 ~ 7월 7일 사이에 주문받은 도서의 주문번호

Image Source Code

1
select orderid as 주문번호, orderdate as 주문날짜 from orders where orderdate between '2024-07-04' and '2024-07-07';

출력 결과

주문번호주문날짜
42024-07-04
52024-07-05
62024-07-07
72024-07-07

Q2-5 : 2024년 7월 4일 ~ 7월 7일 사이에 주문받은 도서를 제외한 도서의 주문번호

Image Source Code

1
select orderid as 주문번호, orderdate as 주문날짜 from orders where orderdate not between '2024-07-04' and '2024-07-07';

출력 결과

주문번호주문날짜
12024-07-01
22024-07-03
32024-07-03
82024-07-08
92024-07-09
102024-07-10

Q2-6 : 성이 ‘김’씨인 고객의 이름과 주소

Image Source Code

1
select name as 고객이름, address as 고객주소 from customer where name like '김%';

출력 결과

고객이름고객주소
김연아대한민국 서울
김연경대한민국 경기도

Q2-7 : 성이 ‘김’씨이고 이름이 ‘아’로 끝나는 고객의 이름과 주소

Image Source Code

1
select name as 고객이름, address as 고객주소 from customer where name like '김%' and name like '%아';

출력 결과

고객이름고객주소
김연아대한민국 서울
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.