删除查询GROUP_CONCAT中的空格

时间:2016-05-04 10:19:17

标签: mysql

我有这样的查询:

SELECT a.CONTAINER, GROUP_CONCAT(DISTINCT a.COIL_NO SEPARATOR '; ') AS COIL_NO FROM tb_barang a 
   WHERE DATE(a.TGL_TRANSFER_SYSTEM)  = "2016-05-04"

GROUP BY a.CONTAINER
ORDER BY a.CONTAINER ASC

它给我这样的结果:

+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| CONTAINER   | COIL_NO                                                                                                                                                                                        |
+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| MRKU7516008 | DNA07X1B530031612A            ; DNA07X1B530031631A            ; DNA07X1B530031610A            ; DNA07X1A431031620A            ; DNA07X1B530031638A            ; DNA07X1A431031612A             |
| MSKU4469584 | DNA07X1B530031636A            ; DNA07X1B530031615A            ; DNA07X1B530031614A            ; DNA07X1A431031607A            ; DNA07X1B530031635A                                             |
| PONU0415152 | DNA07X1B530031613A            ; DNA07X1A431031635A            ; DNA07X1A431031629A            ; DNA07X1B530031617A            ; DNA07X1A431031626A            ; DNA07X1A431031621A             |
| PONU0551375 | DNA07X1A431031641A            ; DNA07X1A431031613A            ; DNA07X1A431031616A            ; DNA07X1B530031629A            ; DNA07X1B530031620A            ; DNA07X1B530031639A             |
+-------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)

正如您所看到的,字段COIL_NO有很多空白字符,我可以在查询中替换那些空格吗?

任何帮助它如此欣赏。

1 个答案:

答案 0 :(得分:1)

试试这个;)

SELECT a.CONTAINER, GROUP_CONCAT(DISTINCT RTRIM(a.COIL_NO) SEPARATOR '; ') AS COIL_NO FROM tb_barang a 
WHERE DATE(a.TGL_TRANSFER_SYSTEM)  = "2016-05-04"

GROUP BY a.CONTAINER
ORDER BY a.CONTAINER ASC

函数RTRIM将返回删除了尾随空格字符的字符串,请查看string-functions