티스토리 뷰
Best Match Like
Like 절 검색 후 유사한 결과순으로 정렬하기
Item
테이블에서 바람막이
를 검색한다고 했을 때
select name from item i
where i.name like '%바람막이%';
이런식으로 Like절
을 활용하면 바람막이
가 포함된 결과가 나옵니다.
하지만 결과는
바람막이 검은색
바람막이
조금만 막는 바람막이
바람막이 흰색
바람막이
가 포함된 단어가 무작위로 나옵니다.
아래와 같이 하면 좀 더 유사한 결과순으로 정렬을 할 수 있습니다.
select name from item i
where i.name like '%바람막이%'
order by
case when i.name = '바람막이' then 0
when i.name like '바람막이%' then 1
when i.name like '%바람막이%' then 2
when i.name like '%바람막이' then 3
else 4 end;
이런식으로 order by
를 하게되면
바람막이
바람막이 검은색
바람막이 흰색
노란색 바람막이 패딩
조금만 막는 바람막이
정렬된 결과가 나오게됩니다.
감사합니다.
References
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- mapstruct
- Spring
- 웹서비스
- springsecurity
- Java
- 스프링부트
- spring web
- boot
- Security
- JPA
- 개발
- java11
- ResourceHttpReqeustHandler
- QueryDSL
- paawordencoder
- ubuntu
- 스프링부트 시작하기
- API
- 스프링시큐리티
- FastAPI
- 스프링
- 자바
- booleanExpression
- like절
- springboot
- @formula
- 유사결과
- Python
- ControllerAdvice
- howtoinstallnginx
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
글 보관함