1.标题描述:
将某行数据排在前面
2.重点:mysql中INSTR的用法
INSTR(字段名, 字符串);
这个函数返回字符串在某一个字段的内容中的位置, 没有找到字符串返回0,否则返回位置(从1开始);
3.数据库使用案例
1.原始数据
2.返回字符串在某一个字段的内容中的位置
3.将name中包含’哈’的排前面
4.在mybatis中的使用
前端:传入id
(mybatis)xml:
//idString 为传过来的id变量名
select *from user
where 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');