我有以下查询:
SELECT
issue.`sequence` AS issue_sequence,
issue.`description` AS issue_description,
GROUP_CONCAT(DISTINCT(issue_category.`name`) SEPARATOR ', ') AS issue_category_name,
GROUP_CONCAT(DISTINCT(approach.`name`) SEPARATOR ', ') AS approach_name,
issue_approach.`issue_id` AS issue_approach_issue_id,
issue_approach.`approach_id` AS issue_approach_approach_id
FROM
`approach` approach
INNER JOIN `issue_approach` issue_approach ON approach.`id` = issue_approach.`approach_id`
INNER JOIN `issue` issue ON issue_approach.`issue_id` = issue.`id`
INNER JOIN `project` project ON issue.`project` = project.`id`
INNER JOIN `tenant` tenant ON project.`tenant_id` = tenant.`id`
INNER JOIN `issue_category` issue_category ON project.`id` = issue_category.`project`
INNER JOIN `user` user ON tenant.`id` = user.`tenant_id`
WHERE user.id = 1 AND project.id = 1
GROUP BY issue_category_name
ORDER BY issue_category.`name`, issue.`sequence`
我对这条线有问题:
GROUP BY issue_category_name
显然,MySQL 似乎无法按 GROUP_CONCAT 结果的别名进行分组。我不是真正的 SQL 专家,但有没有办法可以使用 GROUP_CONCAT 的结果进行分组?
样本数据;
类别:网络、服务器 问题 ID:1 描述:一些描述 方法:解决问题的一些方法。
基本上,一个问题可以属于一个或多个类别。我为每个问题连接类别。我想要做的是按类别连接的结果对结果进行分组。例如,类别为网络、服务器的组问题。
谢谢。