There is a type field in the Document Table, which stores the article type, including 1 headlines, 2 recommendations, 3 hotspots, and 4 texts ..... 11, 12, 13, etc.
There is a type field in the Document Table, which stores the article type, including 1 headlines, 2 recommendations, 3 hotspots, and 4 texts ..... 11, 12, 13, etc.
This is often the case when designing databases, for example:
There is a type field in the Document Table, which stores the article type, including 1 headlines, 2 recommendations, 3 hotspots, and 4 texts..., 12, and 13.
There is an article that is both toutiao, hotspot, and graphic,
Type is stored in the format of 1, 3, and 4.
How can we use SQL to search for articles with four text standards in all types,
This is the time for our find_in_set to crash.
First look at the syntax of the find_in_set function in the mysql manual:
FIND_IN_SET (str, strlist)
If the str string is in the strlist consisting of N substrings, the return value ranges from 1 to N. A string list is a string consisting of several tokens separated by commas. If the first parameter is a constant string and the second parameter is the type SET column, the FIND_IN_SET () function is optimized and computed in bits. If str is not in strlist or strlist is a null string, the return value is 0. If any parameter is NULL, the return value is NULL. This function cannot run normally when the first parameter contains a comma.
The Code is as follows:
Mysql> SELECT FIND_IN_SET ('B', 'a, B, c, D ');
-> 2
Easy to use
I will give an example of the above situation:
Reference content is as follows:
The Code is as follows:
Select * from article where FIND_IN_SET ('4', type)