MySQL Common method Learning

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.