Blog

[MySQL]01 select의 like절

Author
Summary
select 문에서 특정 유형을 찾는 법
Category
Study
Tags
Database
Favorite
Memory Date
2023/08/04
Cross Reference Study
Related Media
Related Thought
Related Lessons
tag
날짜
작성자
진행상황
진행 전
태그구분
6 more properties
select <column> from <table> like '%?%';
부분적인 텍스트로 포함한 정보를 모두 찾는 쿼리문
select name from users like '%홍';
SQL
복사
마치 CLI에서 반쯤 기억나는 파일명을 찾을 때 키워드를 *.exe , driver.* 처럼 입력하는 것과 같다.
또한 _의 경우 파일명을 찾을 때 키워드인 '???ver.???'과 같다. 대신 정확한 자리수를 알 수있거나 기억하는 경우만 해당된다. 위 예시는 ver.라는 문자열을 포함한 양 옆 3자리 문자가 있는 데이터를 찾고 있다. 언더바를 사용하면 %보다 정확한 데이터를 찾을 수 있다.
select <column> from <table> like '___?';
%와 _의 차이는 자리수를 아는가, 모르는가의 차이.
%는 자리수와 관계 없이 특정 문자?가 들어가는 (위치는 관계있다) 모든 레코드, 컬럼,  필드 등 데이터를 찾을 수 있다
왠지 실시간 동적 페이지 구현인 Ajax에서 활용하면 좋을 것 같다 생각이 든다. 이전 Ajax 실습을 어떻게 구현했엇는지 살펴봐야겠다..
#[퀴즈] 포인트가 20000점보다 많은 유저만 뽑아보기! show tables; select * from users; select * from orders; select * from point_users; #<< select * from point_users where point > 20000; #[퀴즈] 성이 황씨인 유저만 뽑아보기 select * from users; select * from users where name like '황%'; #[퀴즈] 웹개발 종합반이면서 결제수단이 CARD인 주문건만 뽑아보기! select * from orders; select * from orders where payment_method = 'card'; #[퀴즈] 결제수단이 CARD가 아닌 주문데이터만 추출해보기 select * from orders; select * from orders where payment_method != 'card'; #[퀴즈] 20000~30000 포인트 보유하고 있는 유저만 추출해보기 select * from users; select * from point_users; select * from point_users where point BETWEEN 20000 and 30000; #[퀴즈] 이메일이 s로 시작하고 com로 끝나는 유저만 추출해보기 select * from users; select * from users where email like 's%com'; #[퀴즈] 이메일이 s로 시작하고 com로 끝나면서 성이 이씨인 유저만 추출해보기 select * from users; select * from users where email like 's%com' and name like '이%'; #성이 남씨인 유저의 이메일만 추출하기 select * from users; select email from users where name like '남%'; #Gmail을 사용하는 2020/07/12~13에 가입한 유저를 추출하기 select * from users; select * from users where email like '%gmail%' and created_at BETWEEN '2020-07-12' and '2020-07-14'; #Gmail을 사용하는 2020/07/12~13에 가입한 유저의 수를 세기 select * from users; select count(*) from users where created_at BETWEEN '2020-07-12' and '2020-07-13'; #naver 이메일을 사용하면서, 웹개발 종합반을 신청했고 결제는 kakaopay로 이뤄진 주문데이터 추출하기 select * from users; select * from orders o; select * from orders where email like '%naver%' and course_title like '웹개발 종합반' and payment_method = 'kakaopay';
SQL
복사