简体   繁体   中英

Number of elements in Group_Concat

Is there a way to get the Counts of elements in Group_Concat? eg When I tried

SELECT c.postcode
     , c.customerID
     , e.engforename
     , e.engsurname
     , j.jobbookeddate
     , p.conumber
     , j.type
     , GROUP_CONCAT(s.serialnumber) 
     , GROUP_CONCAT(fk_jbleID) 
  FROM ...

All I need is number of elements in a GROUP_CONCAT.

Try this

SELECT  *,
        LENGTH(C1) - LENGTH(REPLACE(C1, ',', ''))+1 AS Count_fk_jbleID,
        LENGTH(C2) - LENGTH(REPLACE(C2, ',', ''))+1 AS Count_fk_jbleID
FROM 
(
SELECT c.postcode
     , c.customerID
     , e.engforename
     , e.engsurname
     , j.jobbookeddate
     , p.conumber
     , j.type
     , GROUP_CONCAT(s.serialnumber)  AS C1
     , GROUP_CONCAT(fk_jbleID) AS C2
FROM Table1
) AS T

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