Home >Backend Development >PHP Tutorial >How to use round function Share how to use MySQL's FIND_IN_SET function
Many times we have this situation when designing the database, for example:
There is a type field in the article table, which stores the article type, including 1 headline, 2 recommendation, 3 hot spots, 4 pictures and text... 11, 12, 13, etc.
Now there is an article that is both a headline, a hot spot, and a picture and text.
The type is stored in the format of 1, 3, 4.
How do we use SQL to find all types with 4? As for the article on graphic and text standards,
This is the time for our find_in_set to come into play.
First look at the syntax of the find_in_set function in the mysql manual:
FIND_IN_SET(str, strlist)
If the string str is a character composed of N subchains In the string list strlist, the return value ranges from 1 to N. A string list is a chain of strings separated by ',' characters. If the first argument is a constant string and the second is a column of type SET, the FIND_IN_SET() function is optimized to use bit calculations. If str is not in strlist or strlist is an empty string, the return value is 0. If any parameter is NULL, the return value is NULL. This function will not work properly if the first argument contains a comma (',').
Copy the code The code is as follows:
mysql> SELECT FIND_IN_SET('b','a,b,c,d');
-> 2
Copy the code The code is as follows:
select * from article where FIND_IN_SET('4',type)
The above introduces how to use the round function. Sharing how to use the MySQL FIND_IN_SET function, including how to use the round function, I hope it will be helpful to friends who are interested in PHP tutorials.