SELECT A.id ,A.Prospect_Id, GROUP_CONCAT(DISTINCT A.MYVIEW SEPARATOR ' , ') AS myview
FROM
(SELECT id, Prospect_Id, CONCAT(Current_Status, '(', count(Current_Status), ')') AS MYVIEW
FROM prospectdata1
GROUP BY Prospect_Id) A
GROUP BY A.prospect_id
HAVING myview REGEXP 'PHONE_FOLLOW_UP.*DUPLICATE'
答案 0 :(得分:0)
您需要同时按Prospect_Id和Current_Status分组:
SELECT MIN(MinId) AS id
, Prospect_Id
, GROUP_CONCAT(CONCAT(Current_Status, '(', SUM(Cnt), ')') SEPARATOR ' , ') AS myview
FROM (
SELECT Prospect_Id
, Current_Status
, COUNT(*) Cnt
, MIN(id) MinId
FROM prospectdata1
WHERE Current_Status REGEXP 'PHONE_FOLLOW_UP.*DUPLICATE'
GROUP BY Prospect_Id
, Current_Status
) A
GROUP BY prospect_id