The use of InStr functions in MySQL
INSTR (field name, String) This function returns the position of the string in the contents of a field, returns 0 if no string is found, or returns the position (starting at 1) SELECT * from Tbltopic ORDER by INSTR (Topictitle, ' ha ') > 0 DESC SELECT INSTR (topictitle, ' ha ') from Tbltopic |
Use InStr mates in to sort in MySQL
Sort the instr result as a column, sorted by it
Select id,1 from world_guide where id = 32unionselect * FROM (SELECT ID, InStr (' 30,35,31, ', ' id+ ', ') as D fromworld_blog wher E 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
Fields: Names name
Tom
Harry
Table B
Fields: Titles title
Information one three release
Information of the second king released
Information three-sheet three release
Leaderboard, sort by the name of table a like% ' name '% matches the number of the title of Table B
Leaderboard Example
Zhang 32
Wang 51
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
The use of InStr functions in MySQL