开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜