mysql1054-“字段列表”中的未知列

lf3rwulv  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(432)
SELECT 
  id, 
  Prospect_Id, 
  GROUP_CONCAT(Current_Status ORDER BY id) AS myview, 
  GROUP_CONCAT(myview) AS myview1 
FROM prospectdata1 
GROUP BY Prospect_Id 
HAVING myview REGEXP 'PHONE_FOLLOW_UP.*DUPLICATE'

我想在第二组concat中显示myview数据。。

piah890a

piah890a1#

您可以使用子查询,因为此时列别名对于所选的不同列不可见。我假设你需要第二级的聚合 Prospect_Id 唯一标识行,因为您不是按 id .
使用子查询:

SELECT
  id, Prospect_Id, myview, GROUP_CONCAT(myview) AS myview1
FROM (
  SELECT 
    id, Prospect_Id, GROUP_CONCAT(Current_Status ORDER BY id) AS myview,
  FROM prospectdata1 
  GROUP BY Prospect_Id 
  HAVING myview REGEXP 'PHONE_FOLLOW_UP.*DUPLICATE'
) t
GROUP BY Prospect_Id

相关问题