Environment
CREATE TABLE phople ( ID int (one) NOT null primary key auto_increment, name Char (a) not NULL, sex int (1) not n ull default ' 0 ', degree double (2)), insert into Phople value (null, ' en ', ' 0 ', ' 0 '); INSERT into Phople value (NULL, ' Az ', ' 1 ', ' n '); insert into Phople value (null, ' AA ', ' 1 ', ' + '); insert into Phople value (NULL, ' ad ', ' 1 ', ' 44 ');
1. Select group_concat(name) from Phople; # # Simply link all the Name field values together.
Running Result: Zh,az,aa,ad
Select group_concat(name) from phople Group by sex; # # after the sex group. Concatenate the Name field of the group.
Operation Result:
Zh
Az,aa,ad
Select group_concat(name, ' | | ') from phople Group by sex; # # Default link is ', '; You can change the link symbol here.
Operation Result:
zh| |
az| |,aa| |,ad| |
2. Ifnull method
MYSQL ifnull (EXPR1,EXPR2)
If EXPR1 is not Null,ifnull () returns EXPR1, it returns EXPR2. Ifnull () returns a numeric or string value, depending on the context in which it is used.
3. IF method
IF (EXPR1,EXPR2,EXPR3)
If Expr1 is true (expr1<>0 and Expr1<>null), then if () returns EXPR2, otherwise it returns EXPR3. IF () returns a numeric or string value, depending on the context in which it is used.
Mysql> Select IF (1>2,2,3);
3
4. CONCAT (str1,str2,...) The function that the string is linked to.
Returns the string that results from the connection parameter. If any one of the arguments is NULL, the return value is null.
5. Find_in_set (str, strlist);
Mysql> Select Find_in_set (' B ', ' a,b,c ');
>2
Returns the first number of B in the ' A,b,c ' string. Note that the ' a,b,c ' string must be separated by ', '. Otherwise returns 0, not valid.
MySQL Common method Learning