데이터베이스 실습을 할 때
query문을 만들기가 쉽지 않다. 항상 기본으로 깔려 있어야 하는 문법이 있다.
유명한 madang서점에 고객이 되어 질문을 작성해 본다.
1.도서번호가 1인 도서의 이름
mysql>
select bookname
from book
where bookid=1;
2.가격이 2만 원 이상인 도서명
select bookname
form book
where price>=20000;
3.박지성(1번고객)의 총 구매액
select sum(saleprice) "총구매액"
from orders
where custid=1;
4.박지성(1번 고객)이 구매한 도서수
select count(*)
from orders
where custid=1;
two.마당서점 운영자와 경영자가 요구하는 질문들
1.마당서점 도서의 총 개수
select count( *)
from book;
2.마당서점에 도서를 출고하는 출판사 갯수
mysql>select count(publisher)
-> from book;
3.모든 고객의 이름, 주소
select name, address
from customer;
4.2013년 7월 4일~ 7월 7일 사이에 주문받는 도서의 주문번호
select orderid
from orders
where orderdate beetween "2013-07-04" and "2013-07-07";
5.2013년 7월 4일 ~ 7월 7일 사이에 주문받은 도서를 제외한 도서 주문번호
select orderid
from orders
where orderdate NOT beetween "2013-07-04" and "2013-07-07";
6.성이 '김'씨인 고객의 이름과 주소
select name, address
from customer
where name LIKE '김%';
7.성이 '김'씨이고 이름이 '아'로 끝나는 고객 이름과 주소
select name, address
from customer
where name LIKE '김%아';
'MySQL_DB' 카테고리의 다른 글
DB에서 TABLE 만들고 Foreign Key 생성하기 (0) | 2021.04.19 |
---|---|
[Spring]MyBatis에서 DB 확인할 때 필요한 쿼리Query (0) | 2021.04.19 |
테이블 만들기 와 데이터 입력하기 (0) | 2021.04.12 |
SQL_Developer 로 아이디와 패스워드 생성하기 (0) | 2021.04.09 |