like : 문자열 안에 원하는 문자가 들어있는지 검색
-- 책 제목에 the 가 들어있는 데이터를 가져오시오.
-- 책 제목이 the 인거 가져오시오. 와는 완 전 히 다른것!!
select *
from books
where title = 'the';
select *
from books
where title like '%the%';
-- %는 "the" 앞, 뒤, 또는 둘 다의 어떤 문자열이든 올 수 있다는 것을 의미
-- 책 제목에 시작이 the 로 시작하는 데이터를 가져오시오.
select *
from books
where title like 'the%';
-- stock_quantity 의 숫자가, 두 자리인 데이터만 가져오시오.
-- 언더스코어 사용! __
select *
from books
where stock_quantity like '__';
-- __ 는 두 개의 문자를 가진 문자열을 검색
-- pages 수는 100보다 크고 책 제목에 the 가 들어간 책을 가져오되
-- 재고수량 내림차순으로 데이터를 3개만 가져오시오.
select *
from books
where pages > 100 and title like '%the%'
order by stock_quantity desc
limit 3;
-- 책 제목에, talk 가 없는 데이터만 가져오시오.
select *
from books
where title not like '%talk%';
'MySQL' 카테고리의 다른 글
[MySQL] 데이터 그룹화하여 처리 group by, having (0) | 2024.05.14 |
---|---|
[MySQL] 데이터 집계 함수 count, sum, avg, max, min (0) | 2024.05.14 |
[MySQL] 데이터를 가공 키워드 distinct, order by, limit (0) | 2024.05.14 |
[MySQL] 문자열 컬럼 데이터 가공 함수 concat(), substring(), replace(), reverse(), char_length(), upper(), lower() (0) | 2024.05.13 |
[MySQL] 테이블 데이터 삭제 Delete (0) | 2024.05.13 |