serversql 分页查询,按匹配精准度排序
SELECT S_INFO_WINDCODE, S_INFO_CODE, S_INFO_NAME, S_INFO_COMPNAME, S_INFO_COMPNAMEENG, S_INFO_EXCHMARKET, S_INFO_LISTBOARD, S_INFO_LISTDATE, S_INFO_DELISTDATE, S_INFO_PINYIN, S_INFO_LISTBOARDNAME, S_INFO_COMPCODE FROM AShareDescription WHERE S_INFO_WINDCODE LIKE '%${sInfoWindcode}%' ORDER BY (case when S_INFO_WINDCODE='${sInfoWindcode}' then 1 when S_INFO_WINDCODE like '${sInfoWindcode}%' then 2 when S_INFO_WINDCODE like '%${sInfoWindcode}%' then 3 when S_INFO_WINDCODE like '%${sInfoWindcode}' then 4 else 5 end) ASC OFFSET '${startNum}' ROWS FETCH NEXT '${startSize}' ROWS ONLY
MySQL 根据字符的长度排序,name 字段使用关键字模糊查询之后,再使用
char_length
函数,获取 name 字段的字符长度,然后按长度升序
。
sql :如下
select * from brand where name like '%苏三%' order by char_length(name) asc, locate('苏三',name) asc limit 5,5;
有几种方法可以学习:
https://mp.weixin.qq.com/s/2zHSzHpKlq2saTTMLX9SSg
标签:INFO,sInfoWindcode,分页,模糊,when,查询,like,WINDCODE,name From: https://www.cnblogs.com/gina11/p/16805549.html