将某数据排前面

来源:互联网 发布:淘宝助理下载 编辑:程序博客网 时间:2024/06/09 19:32

1.标题描述:

将某行数据排在前面

2.重点:mysql中INSTR的用法

INSTR(字段名, 字符串);这个函数返回字符串在某一个字段的内容中的位置, 没有找到字符串返回0,否则返回位置(从1开始);

3.数据库使用案例

1.原始数据
这里写图片描述
2.返回字符串在某一个字段的内容中的位置
这里写图片描述
3.将name中包含’哈’的排前面
这里写图片描述

4.在mybatis中的使用

前端:传入id(mybatis)xml:
//idString 为传过来的id变量名select *from userwhere 1=1 order by     <if test="idString!=null">        instr(id,#{idString})desc,    </if>    brithday desc

5.instr的妙用

instr和like%str%进行模糊查询时,效果相同,但是instr效率更高。
select *from student where name like "%xiao%";select *from student where INSTR(name,'xiao');
阅读全文
0 0
原创粉丝点击