mysql CONCAT、CONCAT_WS、GROUP_CONCAT()

1、CONCAT()

Function for connecting the plurality of strings into a single string.

SELECT CONCAT(id,'-',sex) AS a FROM recruitment_requirement

 

 condition:

id sex and must be non-null

SELECT CONCAT(id,'-',centre_id) AS id_sex FROM recruitment_requirement

 

note:

id still non-null, but centre_id is null, the result of a problem

 

2、CONCAT_WS()

Representative CONCAT With Separator, is CONCAT () is a special form.

The first parameter is the other argument separator. Positions separator placed between two strings to be connected. The separator can be a string or other parameters. If the separator is NULL, the result to NULL. NULL function ignores any parameter values ​​delimiter. But CONCAT_WS () will not ignore any empty string, but will ignore all NULL).

SELECT CONCAT_WS('-',id,sex) AS id_sex FROM recruitment_requirement

 

 

id sex with a non-null

SELECT CONCAT_WS('-',id,centre_id) AS id_sex FROM recruitment_requirement

 id non-null, but is null centre_id

. 3, the GROUP_CONCAT ()
the GROUP_CONCAT function returns a string result, which is connected by a value in the packet combination.

 (Id non-null, but it centre_id be null)

SELECT GROUP_CONCAT(id) FROM recruitment_requirement 

SELECT id,GROUP_CONCAT(id) FROM recruitment_requirement 

SELECT GROUP_CONCAT(centre_id) FROM recruitment_requirement

 

SELECT id,GROUP_CONCAT(centre_id) FROM recruitment_requirement

 

 

Published 21 original articles · won praise 0 · Views 2259

Guess you like

Origin blog.csdn.net/hfaflanf/article/details/103261382