How to calculate aggregate function SUM on an alias column?
SELECT a.question_id,
a.level,
Count(a.question_id) AS rank,
Sum(rank) AS total
FROM logs AS a,
question AS b
WHERE a.question_id = b.q_id
AND a.level = '2'
GROUP BY a.question_id
ORDER BY rank DESC
SUM(COUNT(a.step_id)) AS total. Aliases are only available in GROUP BY, ORDER BY or HAVING (aside from direct output).GROUP BY a.question_idand also COUNT() and SUM() on the same field?