군침이 싹 도는 코딩
MySQL 데이터를 가져오는 여러 방법 (!=,not like,between A and B,in,is null) 본문
Database/MySQL
MySQL 데이터를 가져오는 여러 방법 (!=,not like,between A and B,in,is null)
mugoori 2022. 12. 7. 17:12select *
from books
where released_year != 2017;
# not equal 파이썬의 != 와 같은 뜻으로
그것이 포함되지 않은것을 다 가져오라는 뜻이다
select *
from books
where title not like '%w%';
# like 앞에 not을 사용해 마찬가지로
이것이 포함되지 않은것을 다 가져오라는 뜻
select *
from books
where released_year >= 1990 and released_year <= 2015 ;
select *
from books
where released_year between 1990 and 2015;
# 위 같이 부등식이 두개인 경우 컬럼을 두번써줘야 하지만
between A and B 를 사용해 간단하게 바꿀수도 있다
-- 출간년도가 2002년, 2004년, 2006년, 2012년, 2015년이 아닌 책들의 데이터만 가져오세요
select *
from books
where released_year in (2002,2004,2006,2012,2015);
# in 을 사용해 여러개가 포함된 데이터를 가져올수도 있다
in 앞에 not 을 사용해 그것을 제외한것도 가져올수있다
-- comments 테이블에서 updated_at 컬럼이 null 인 데이터를 가져오시오.
select *
from comments
where updated_at is null;
# is null 을 이용해 null 인 데이터를 가져올수도 있다
이것 역시 not 을 사용해 null 이 아닌 데이터도 가져올수있다
'Database > MySQL' 카테고리의 다른 글
MySQL 테이블을 합치기 (join) (0) | 2022.12.08 |
---|---|
MySQL 조건문 처리하는 방법 (case,if) (0) | 2022.12.07 |
MySQL 시간의 차이를 구하는 함수 (datediff,date_add,date_sub,interval) (0) | 2022.12.07 |
MySQL 현재 시간을 가져오고 싶을때 함수 (now,curdate,curtime) (0) | 2022.12.07 |
MySQL 시간 데이터를 사람이 보기 편하게 바꾸기 (date_format) (0) | 2022.12.07 |