Usage of INSTR function in mysql
INSTR(field name, string)
This function returns the position of the string in the content of a field, returns 0 if the string is not found, otherwise returns the position (starting from 1)
SELECT * FROM tblTopic ORDER BY INSTR( topicTitle, 'ha' ) > 0 DESC
SELECT INSTR( topicTitle, 'ha' ) FROM tblTopic
MySQL uses instr and IN sorting to sort
the instr result as a column
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;
output
+----+ ---+
| id | 1 |
+----+---+
| 32 | 1 |
| 30 | 1 |
| 35 | 4 |
| 31 | 7 |
+----+---+
4 rows in set, 6 warnings (0.02 sec)
Table A
Field: name name
Zhang Sanwang
five
Form B
field: title title
information one three publishing
information two king five publishing
information three three three publishing
rankings , according to the name of table A like %'name'% to match the title of table B Sort by number,
ranking example
Zhang San 2
Wang Wu 1
select name,count(b.title) from a inner join b on instr(b.title,a.name)>0
group by name
order by count(b.title )
select name,(select count(*) from table B where instr(title, table A.name)
from table A
order by 2 desc
from: http://blog.csdn.net/zyyr365/article/details/5603555
Usage of INSTR function in mysql
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=326828099&siteId=291194637
Recommended
Ranking