- BETWEEN: 값과 값 사이의 값을 구하고 싶을때
SELECT title, released_year FROM books
WHERE released_year BETWEEN 2004 AND 2015;
SELECT title, released_year FROM books
WHERE released_year NOT BETWEEN 2004 AND 2015;
- IN, NOT IN: 포함된 값을 구하거나 포함되지 않은 값을 구하고 싶을때
SELECT
title,
author_lname
FROM books
WHERE author_lname='Carver' OR
author_lname='Lahiri' OR
author_lname='Smith';
=>
SELECT title, author_lname FROM books
WHERE author_lname IN ('Carver', 'Lahiri', 'Smith');
SELECT title, released_year FROM books
WHERE released_year != 2000 AND
released_year != 2002 AND
released_year != 2004 AND
released_year != 2006 AND
released_year != 2008 AND
released_year != 2010 AND
released_year != 2012 AND
released_year != 2014 AND
released_year != 2016;
=>
SELECT title, released_year FROM books
WHERE released_year NOT IN
(2000,2002,2004,2006,2008,2010,2012,2014,2016);
SELECT title, released_year FROM books
WHERE released_year >= 2000 AND
released_year % 2 != 0 ORDER BY released_year DESC;
- CASE: 케이스를 정하고 값을 구하고 싶을때
SELECT title, stock_quantity,
CASE
WHEN stock_quantity BETWEEN 0 AND 50 THEN '*'
WHEN stock_quantity BETWEEN 51 AND 100 THEN '**'
ELSE '***'
END AS STOCK
FROM books;