开发者

How to order by number of keywords found in sql/namedQuery

开发者 https://www.devze.com 2023-02-12 16:55 出处:网络
I created a query with a like and a or select * from xxx where title like (\'%bon%\') or title like (\'%test%\')

I created a query with a like and a or

select * from xxx where title like ('%bon%') or title like ('%test%')

I receive a result with : bonjour je test bonjour test bonjour test

And I would like ordered by number of word in title : bonjour je test test bonjour bonjour test

I use Grails with namedQueries.

Is it possible to do that ?

开发者_开发技巧

Thanks


You can use this little trick to count the number of space characters and sort by that.

select * from xxx where title like ('%bon%') or title like ('%test%')
order by (LEN(title) - LEN(REPLACE(title, ' ', '')))
0

精彩评论

暂无评论...
验证码 换一张
取 消