AND : 조건을 모두 충족하는 것
페이지(pages)가 100이상이고 200이하인 데이터 출력
100이상이고 200이하의 조건을 모두 충족해야하므로 and 사용
select * from books where pages >= 100 and pages <= 200;
OR : 조건 중 하나라도 만족하는 것
작가의 성(author_lname)이 Chabon이거나 Eggers인 데이터 출력
Chabon과 Eggers 중 둘 중 하나라도 만족하면되므로 or 사용
select * from books where author_lname like 'Chabon' or author_lname like 'Eggers';
-- author_lname 이름이 'Eaggers'이고 년도는 2000년 이후이며,
-- 제목에 novel 이라고 들어간 데이터를 가져오세요.
select *
from books
where author_lname = 'Eggers' and released_year > 1900 and title like '%novel%';
-- author_lname이 Egger 이거나 출간년도가 2010보다 큰 책을
-- 가져오시오.
select *
from books
where author_lname = 'Eggers' or released_year > 2010;
-- 무엇과 무엇 사이의 데이터를 가져올때 !!
-- 년도가 2004년부터 2015년 사이의 책 데이터를 가져오시오.
select *
from books
where released_year >= 2014 and released_year >= 2015;
select *
from books
where released_year between 2004 and 2015 ;
-- author_lname 이 'Carver' 이거나 'Lahir' 이거나 'Smith' 인 데이터만 가져오시오.
select *
from books
where author_lname in ( 'Carver', 'Lahiri', 'Smith' );
-- 년도가 2000년 이후에 나온 책들은 Modern 이라고 하고,
-- 그렇지 않는 책들은 Old 라고 새로운 컬럼을 만들어서 가져오세요.alter
select * ,
case
when released_year >= 2000 then 'Modern'
else 'Old'
end as Genre
from books;
-- stock_quantity 가 0~50 사이면, * (별표한개)
-- stock_quantity 가 51~100 사이면, * (별표한개)
-- stock_quantity 가 그 외에는 *** (별표3개)
select * ,
case
when stock_quantity between 0 and 50 then '*'
when stock_quantity between 51 and 100 then '**'
else '***'
end as star
from books;