mysql a few more practical function

1. there was such a demand:

 

 

 You can use the following functions:

Syntax: FIND_IN_SET (str, strlist).

definition:

1. If the string str strlist a string list consisting of N sub-chains, the return value in the range between 1 to N.

2 is a list of strings is a string consisting of a number ',' symbol separate from the chain.

3. If the first parameter is a constant string, and the second is typeSET column, the FIND_IN_SET () function is optimized using bit calculation.

4. If not strlist str strlist or empty string, the return value is 0.

5. any parameter is NULL, return value is NULL. This will not work when the first argument function contains a comma ( ',').

strlist: a comma a "," link string, for example: "a, b, c, d", similar to the string form of the value of SET type is linked to a comma.

Example: SELECT FIND_IN_SET ( 'b', 'a, b, c, d'); // return value 2, i.e. the second value

2. there was such a demand:

You need to check out the id, the specified delimiter stitching. We usually check out the list, in the service layer stitching, in fact, it can directly query the splicing process,

You can use the following functions:

Grammatical structures:

 GROUP_CONCAT([DISTINCT] expr [,expr ...] [ORDER BY {unsigned_integer | col_name | expr} [ASC DESC] [,col_name ...]] [SEPARATOR str_val])

DISTINCT: removing duplicate values

expr [, expr ...]: one or more fields (or expressions)

ORDER BY {unsigned_integer | col_name | expr} [ASC | DESC] [, col_name ...]: sorted according field or expression may be a plurality of

SEPARATOR str_val: separator (default comma)

Following examples:

 

Guess you like

Origin www.cnblogs.com/ysq0908/p/12038342.html