본문 바로가기

SQL(Structured Query Language:)

SQL : 문자열 검색에 유용한 like 사용법

-- 문자열 포함 (Serach)   : like 키워드
-- 내가 찾고자 하는 문자열이, 컬럼에 포함되어 있는지 확인하는 방법.

-- 책 제목에 the 라고 들어있는 책만 가져오시오.

select *
from books
where title like the;


-- the로 시작하는 책만 가져오시오.
select *
from books
where title like '%the' ;

-- author_fname애 da라고 들어있는 작가의
-- 책 제목, author_fname, 페이지수를 가져오시오.
select title, author_fname, pages
from books
where author_fname like '%da%' ; 

-- 언더스코어 기호를 이용한 쿼리문.
-- 언더스코어 갯수만큼, 숫자가 2자리 수인지 3자리수인지 자리수를 나타낸다.
select *
from books
where stock_quantity like '___' ;