有一个子查询,它使用GROUP_CONCAT将结果分组在一个字段中。
但是使用此查询需要3秒钟才能运行此查询,否则需要0.05秒钟。
我已经索引了annex.actionid和action.actionid是PK。
有提高性能的解决方案吗?
SELECT
action.actiondate, acc.acc, acc.acccount
FROM
`action`
LEFT JOIN
(SELECT
actionid,
GROUP_CONCAT(accessory) AS acc,
COUNT(actionid) AS acccount
FROM
accessorieslink
GROUP BY actionid) AS acc
ON acc.actionid = action.actionid
最佳答案
使用以下方法可能会更好:
SELECT
a.actiondate,
GROUP_CONCAT(IFNULL(al.accessory,'') ) as acc,
SUM(IF(al.actionid IS NULL,0,1)) as acccount
FROM
`action` a
LEFT JOIN accessorieslink al
ON al.actionid = a.actionid
GROUP BY
a.actionid
ORDER BY
NULL
关于mysql - 子查询中的缓慢GROUP_CONCAT,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17041098/