我在查询时遇到问题:
SELECT a.created_by,
CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author
FROM #__content AS a
LEFT JOIN #__users AS ua ON ua.id = a.created_by
WHERE a.state='1'
GROUP BY a.created_by
ORDER BY author
返回的结果在某种程度上是正确的,但问题是它按ID分组,但仍返回重复的一些名称(这些名称相同,但具有不同的ID)。
如果这些名称具有不同的ID,如何将它们分组?
在此先感谢您的帮助。
最佳答案
也按作者分组
SELECT
a.created_by,
CASE WHEN a.created_by_alias > ' ' THEN a.created_by_alias ELSE ua.name END AS author
FROM #__content AS a
LEFT JOIN #__users AS ua ON ua.id = a.created_by
WHERE a.state='1'
GROUP BY a.created_by ,author
ORDER BY author
关于php - 在MySQL查询中按问题分组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20261919/