我有以下查询。
SELECT parent.id AS 'id', parent.CA_NAME as 'name', node.level AS 'level', midpoint.level AS 'midpointlevel', SUM(ad.id IS NOT NULL) AS 'count'
FROM
category AS parent,
category AS midpoint,
category AS node
LEFT JOIN ad ON ad.id=node.id
AND ad.status='A'
WHERE (node.`LEFT` BETWEEN parent.`LEFT` AND parent.`RIGHT`)
AND (node.`LEFT` BETWEEN midpoint.`LEFT` AND midpoint.`RIGHT`)
AND midpoint.id='1'
GROUP BY parent.id
HAVING IF(midpoint.level=0, node.level < 2, node.level > 0)
ORDER BY parent.id
我不想选择该midpoint.level AS 'midpointlevel'
部分,但如果我删除它,having 子句会给出一个错误提示:错误代码:1054。'having 子句'中的未知列'midpoint.level'。谁能帮我删除不需要的选择部分。