简体   繁体   中英

limit length of each GROUP_CONCAT values

If I have per example the following table

cliente.nome
peter sampras
john mark
monalisa

the result with

GROUP_CONCAT(DISTINCT cliente.nome ORDER BY cliente.nome SEPARATOR ', ') as client

will be:

peter sampras,john mark,monalisa

Is possible to limit the length of each item so the result is:

pete,john,mona

Yes, you can use SUBSTRING or LEFT in your GROUP_CONCAT call -- I prefer using LEFT for this:

GROUP_CONCAT(DISTINCT LEFT(cliente.nome,4))

SQL Fiddle Demo

GROUP_CONCAT(DISTINCT SUBSTRING(cliente.nome,1,4))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM