왕현성
코딩발자취
왕현성
전체 방문자
오늘
어제
  • 코딩 (277)
    • Python (71)
    • Java (16)
    • MySQL (34)
    • 인공지능 (48)
      • 머신러닝 (16)
      • 딥러닝 (32)
    • 영상처리 (4)
    • Rest API (21)
    • Android Studio (25)
    • streamlit (13)
    • DevOps (22)
      • AWS (9)
      • PuTTY (5)
      • Git (4)
      • Serverless (2)
      • Docker (2)
    • IT 기술 용어 (6)
    • 디버깅 ( 오류 해결 과정 ) (17)

블로그 메뉴

  • 홈
  • 태그
  • 방명록

공지사항

인기 글

태그

  • 비지도학습
  • labelme
  • pytorch
  • unsupervised
  • 영상기술
  • PYTHON
  • UnboundLocalError
  • alibi-detection
  • labelme UnocodeDecodeError
  • get_long_description
  • 의료이미징
  • PIL
  • maskimage
  • 영상처리
  • alibidetect
  • 딥러닝
  • TensorFlow
  • ckpt_file
  • numpy
  • ComputerVision
  • 컴퓨터비전
  • encoding='utf-8'
  • pip install labelme
  • yolov8
  • 기상탐사
  • imageprocessing
  • matplotlib
  • tune()
  • OpenCV
  • 영상처리역사

최근 댓글

최근 글

티스토리

250x250
hELLO · Designed By 정상우.
왕현성

코딩발자취

MySQL - like 검색기능
MySQL

MySQL - like 검색기능

2022. 12. 7. 11:35
728x90
INSERT INTO books (title, author_fname, author_lname, released_year, stock_quantity, pages)
VALUES
('The Namesake', 'Jhumpa', 'Lahiri', 2003, 32, 291),
('Norse Mythology', 'Neil', 'Gaiman',2016, 43, 304),
('American Gods', 'Neil', 'Gaiman', 2001, 12, 465),
('Interpreter of Maladies', 'Jhumpa', 'Lahiri', 1996, 97, 198),
('A Hologram for the King: A Novel', 'Dave', 'Eggers', 2012, 154, 352),
('The Circle', 'Dave', 'Eggers', 2013, 26, 504),
('The Amazing Adventures of Kavalier & Clay', 'Michael', 'Chabon', 2000, 68, 634),
('Just Kids', 'Patti', 'Smith', 2010, 55, 304),
('A Heartbreaking Work of Staggering Genius', 'Dave', 'Eggers', 2001, 104, 437),
('Coraline', 'Neil', 'Gaiman', 2003, 100, 208),
('What We Talk About When We Talk About Love: Stories', 'Raymond', 'Carver', 1981, 23, 176),
("Where I'm Calling From: Selected Stories", 'Raymond', 'Carver', 1989, 12, 526),
('White Noise', 'Don', 'DeLillo', 1985, 49, 320),
('Cannery Row', 'John', 'Steinbeck', 1945, 95, 181),
('Oblivion: Stories', 'David', 'Foster Wallace', 2004, 172, 329),
('Consider the Lobster', 'David', 'Foster Wallace', 2005, 92, 343),
('10% Happier', 'Dan', 'Harris', 2014, 29, 256),
('fake_book', 'Freida', 'Harris', 2001, 287, 428),
('Lincoln In the Bardo', 'George', 'Saunders', 2017, 156, 375);

만약 책 제목에 the가 들어가는 걸 찾고 싶다고 가정 했을때 이렇게 합니다.

select *
from books
where title like 'the';  -- 이럴경우 책 제목이 the인것만 찾기 때문에 아무런 데이터도 나오지 않습니다.

-- 그렇다면 어떻게 해야할까?
select *
from books
where title like '%the%';
-- 이렇게 작성 해주셔야 책 제목에 the가 들어간걸 찾을 수 있다

-- stock_quantity 의 숫자가 두자리인 데이터만 가져오시오. _ 언더스코어로 표시. 문자열에도 적용 가능

select*
from books
where stock_quantity like '__' ;

 

응용 ) 

-- page 수는 100보다 크고, 책 제목에 the가 들어간 책을 가져오되,
-- 재고수량 내림차순으로 데이터를 3개만 가져오시오.

select *
from books
where pages > 100 and title like '%the%'
order by stock_quantity desc
limit 3;

'MySQL' 카테고리의 다른 글

MySQL - 최대값 max() ,최소값 min() , sub query  (0) 2022.12.07
MySQL - 문자열 컬럼의 여러 키워드들 예제풀이  (0) 2022.12.07
MySQL - limit 데이터를 나눠서 가져오는 방법  (0) 2022.12.07
MySQL - 정렬하기(order by) / 오름차순(asc), 내림차순(desc)  (0) 2022.12.07
MySQL - distinct 중복 없는 데이터 보기  (0) 2022.12.07
    'MySQL' 카테고리의 다른 글
    • MySQL - 최대값 max() ,최소값 min() , sub query
    • MySQL - 문자열 컬럼의 여러 키워드들 예제풀이
    • MySQL - limit 데이터를 나눠서 가져오는 방법
    • MySQL - 정렬하기(order by) / 오름차순(asc), 내림차순(desc)
    왕현성
    왕현성
    AI 머신비전 학습일지

    티스토리툴바