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');