mysql中instr函式的用法
instr(欄位名, 字串)
這個函式返回字串在某乙個欄位的內容中的位置, 沒有找到字串返回0,否則返回位置(從1開始)
select * from tbltopic order by instr( topictitle, 'ha' ) > 0 desc
select instr( topictitle, 'ha' ) from tbltopic
mysql中使用instr配合in排序
將instr結果作為一列,按其排序
select id,1 from world_guide where id = 32輸出union
select * from
(select id, instr('30,35,31,',id+',') as d from
world_blog where id in (30,35,31) order by d) as t;
+----+---+| id | 1 |
+----+---+
| 32 | 1 |
| 30 | 1 |
| 35 | 4 |
| 31 | 7 |
+----+---+
4 rows in set, 6 warnings (0.02 sec)
表a
字段:姓名 name
張三王五
表b欄位:標題 title
資訊一 張三發布
資訊二 王五發布
資訊三 張三發布
排行榜,按表a的姓名 like %『name』% 匹配 表b的 title 的條數進行排序,
排行榜樣例
張三 2
王五 1
select 姓名,count(b.title) from a inner join b on instr(b.title,a.姓名)>0
group by 姓名
order by count(b.title)
select
name,(
select
count(*
) from
表b where
instr(title,表a.name)
from
表a orderby2
desc
mysql中的instr 函式的用法
有時,想要在字串中查詢某字串可以使用instr 函式 instr 返回子字串在字串中首次出現的位置 如果沒有找到,則返回0 用法 instr str,substr str 從哪個字串中搜尋 substr 要搜尋的子字串 instr 函式不區分大小寫 mysql instr 函式示例 如圖,在abcd...
Mysql的instr 函式用法
mysql的內建函式instr filed,str 作用是返回str子字串在filed字串的第一次出現的位置。當instr filed,str 0時,表示子符串str不存在於字串filed中,因此可以用來實現mysql中的模糊查詢,與like用法類似。如下 1 instr 函式,為引數 select...
Oracle中的instr函式
在oracle pl sql中,instr函式返回string2在string1中出現的位置,語法如下 例項1.從起始位置開始搜尋,第一次出現子串的位置 sql select instr chen linbo bobo12082119 bo 1,1 from dual instr chen linb...