In every order of operations diagram I’ve seen, SELECT
comes essentially near the very end, and always after GROUP BY
. However, I find it confusing that in the below SQL statement, we declare aliases in the SELECT
statement that can be referenced in the GROUP BY
even though GROUP BY
happens before SELECT
. How is this possible?
SELECT SUM(amount) as 'sum_amt', MONTH(payment_date) as 'm_date'
FROM payment
GROUP BY m_date