Concat, Concat_ws, Group_concat function usage __ function

Source: Internet
Author: User

one, concat () function can connect one or more strings

CONCAT (STR1,STR2,...) returns the string produced by the result of the connection parameter. If any of the arguments are null, the return value is null.

Select Concat (' 11 ', ' 22 ', ' 33 ');
Query results show: 112233


ii. Concat_ws (separator,str1,str2,...)

is a special form of concat (). The first parameter is the separator for the other arguments. The position of the separator is placed between the two strings to which you want to connect. The delimiter can be a string, or it can be another parameter.

Select Concat_ws (', ', ' 11 ', ' 22 ', ' 33 ');
Query Display results: 11,22,33
 
 
  three, Group_concat () group splicing function

Group_concat ([DISTINCT] The field to connect [order by Asc/desc sort field] [Separator ' delimiter]]

Use Group_concat () for one of the following sets of data

| ID |name

|1 | 10|
|1 | 20|
|1 | 20|
| 20|
|3 | 200 |
|3 | 500 |

1, select Id,group_concat (name) from AA Group by ID;

|1 | 10,20,20|
| 20 |
|3 | 200,500|

2, select ID,GROUP_CONCAT (name separator '; ') from the AA group by ID;

|1 | 10;20;20 |
| 20|
|3 | 200;500 |

3, select ID,GROUP_CONCAT (name order BY name Desc) from the AA group by ID;

|1 | 20,20,10 |
| 20|
|3 | 500,200|

4, select Id,group_concat (distinct name) from AA Group by ID;

|1 | 10,20|
| 20 |
|3 | 200,500 |

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.