select * from customer, orders where customer.custid = orders.custid and customer.custid = 1;
select sum(saleprice) from customer, orders where customer.custid = orders.custid and customer.custid = 1;
select * from customer, orders, book where customer.custid=orders.custid and customer.name='박지성' and book.bookid=orders.bookid;
select count(distinct book.publisher) as "박지성이구매한도서의출판사수" from customer, orders, book where customer.custid=orders.custid and customer.name='박지성' and book.bookid=orders.bookid;
select * from customer, orders, book where customer.custid=orders.custid and customer.name='박지성' and book.bookid=orders.bookid;
select book.bookname, book.price from customer, orders, book where customer.custid=orders.custid and customer.name='박지성' and book.bookid=orders.bookid;
select * from customer, orders, book where customer.custid=orders.custid and customer.name='박지성' and book.bookid=orders.bookid;
select 1+2 from customer, orders, book where customer.custid=orders.custid and customer.name='박지성' and book.bookid=orders.bookid;
select book.price - orders.saleprice from customer, orders, book where customer.custid=orders.custid and customer.name='박지성' and book.bookid=orders.bookid;
select book.bookname, book.price, orders.saleprice, book.price - orders.saleprice as "정가와 판매가격의 차이" from customer, orders, book where customer.custid=orders.custid and customer.name='박지성' and book.bookid=orders.bookid;
select 1+2 from dual; --du(dummy) table (al)
select bookname from book where (박지성이 구매하지 않았다.)
select bookname from book; -- 조건 구매하지 않음 ;
select bookname from book where bookid not in (1,2,3);
select orders.bookid from customer, orders where customer.custid=orders.custid and customer.name='박지성' ;
select bookname from book where bookid not in (select orders.bookid from customer, orders where customer.custid=orders.custid and customer.name='박지성' );
도서를 구매한 적이 있는 고객( 구매 내역 중 고객이 있냐? orders 테이블 내에 고객 id 가 있으면 구매한 고객)
도서를 구매한 적이 있는 고객의 이름을 검색(조인 이용)
1) select * from orders, customer where orders.custid= customer.custid;
select customer.name from orders, customer where orders.custid= customer.custid;
select distinct customer.name from orders, customer where orders.custid= customer.custid;
도서를 구매한 적이 있는 고객의 이름을 검색(서브 쿼리 이용)
고객의 이름을 검색 쿼리
조건 : 도서를 구매한 적이 있는(in)
select name FROM customer;
select * from orders;
select distinct custid from orders;
select name FROM customer where custid in (1,2,3,4);
select name FROM customer where custid in (select distinct custid from orders);
select name FROM customer where custid not in (select distinct custid from orders);
select max(price) from book;
select * from book ;
select count(*) from book GROUP by bookname;
select sum(price) from book GROUP by bookname;
select avg(price) from book GROUP by bookname;
select min(price) from book GROUP by bookname;
select max(price) from book GROUP by bookname;
select * from orders, customer where orders.custid= customer.custid;
select customer.name, sum(orders.saleprice) from orders, customer where orders.custid= customer.custid GROUP by customer.name;
select customer.name, book.bookname from orders, customer, book where orders.custid= customer.custid and orders.bookid = book.bookid;
select book.bookname, book.price, orders.saleprice, book.price - orders.saleprice FROM book, orders where orders.bookid = book.bookid;
select max(book.price - orders.saleprice) FROM book, orders where orders.bookid = book.bookid;
select *
from book, orders
where orders.bookid = book.bookid
and
book.price - orders.saleprice = (select max(book.price - orders.saleprice)
FROM book, orders
where orders.bookid = book.bookid);
select avg(saleprice) from orders;
select avg(orders.saleprice) from orders;
select customer.name, avg(orders.saleprice) from orders, customer where orders.custid= customer.custid GROUP by customer.name;
select customer.name, round(avg(orders.saleprice)) from orders, customer where orders.custid= customer.custid GROUP by customer.name;
select customer.name, round(avg(orders.saleprice))
from orders, customer
where orders.custid= customer.custid
GROUP by customer.name
having round(avg(orders.saleprice)) > (select avg(orders.saleprice) from orders);