실행하기 - ctrl + enter
주석처리 - (ctrl + /)
select 필드 from 테이블명; (조회하기)
(실무에서는 이렇게 조회하면 안됨 데이터가 너무 많이 실행되서)
select * from help;
help라는 테이블의 모든 필드를 불러오기



select * from book WHERE bookname = 'value값';
=대신 like를 사용가능



select DISTINCT publisher from book;
select count(DISTINCT publisher) as 명절때돌릴선물갯수 from book;
select count(DISTINCT publisher) 명절때돌릴선물갯수 from book; --집계함수(SUM, avg, COUNT, max, min)
select * from emp e, dept d where e.deptno = d.deptno;
select * from emp e, dept d where e.deptno = d.deptno order by e.empno;





select name from customer where custid in(select custid from orders where bookid in(select bookid from book where publisher = '대한미디어'));
select * from orders;
select bookid from book where publisher = '대한미디어';
select custid from orders where bookid in(select bookid from book where publisher = '대한미디어');
select * from customer;
SELECT sum(saleprice) as 총판매액, avg(saleprice) as 평균값, max(saleprice) 최고가, min(saleprice) 최저가 from orders;
select * from orders group by custid; (group by 함수는 집계함수(sum, count, avg, min, max)와 같이 사용해야함)
select custid, sum(saleprice) from orders group by custid;
//select 다음 custid를 입력했을때 다음 필드인 sum(saleprice)의 앞에 custid이랑 price가 일치하는지 확인할수있음
--select custid, sum(saleprice) from customer,orders group by customer.custid = orders.orderid order by customer.custid = orders.orderid;



조회 오류 예시

특정 글자가 포함된 경우를 조회해보기

--select * from book WHERE bookname = '축구의 역사';
--select * from book WHERE bookname like '축구의 역사';
--SELECT price,bookname from book;
SELECT * from customer;
SELECT * from customer where name = '김연아' ; -- 정확하게 김연아
--SELECT * from customer where name = "김연아" ; 불가
--SELECT * from customer where name = 김연아 ; 불가
SELECT * from customer where name like '김연아' ;
-- 박씨 성만 가진 사람만 나오게 하고 싶을 경우
select * from customer where name = '박%'; -- 정확하게 해당값 =
select * from customer where name like '박지성'; -- 문자열은 like를 주로 사용하시면 됨
-- %가 의미하는 바는 문자열에서 무엇이든을 의미
select * from customer where name like '박%'; -- '박' 이라는 문자가 들어가는 형태로 하고자 할경우 like
select * from customer;
--and
select * from customer where name like '박지성' and address like '영국%';
-- or
select * from customer where name like '박지성' or name like '박세리';
--SELECT address from customer where name = '김연아' ;
--SELECT address, phone from customer where name = '김연아' ;
--SELECT phone, address from customer where name = '김연아' ;
select * from customer;
select * from orders where custid=2;
위 예시는 2번에 걸쳐서 실행하므로 효율이 떨어짐 ! 따라서 두개의 테이블을 합쳐서(join) 보고 싶다.
select * from customer, orders;
select * from customer, orders where orders.custid = customer.custid and customer.name like '%김연아%';
select sum(saleprice) from customer, orders where orders.custid = customer.custid and customer.name like '%김연아%';
의미없는 나열

김연아라는 이름의 orderid와 custid가 일치하는 데이터

