If you refer column alias in the where caluse, you will get the error:
SELECT YEAR(transaction_date) AS YEAR,amount FROM dev.sale
You get the error
Invalid column name ‘year’.
It is because the column alias are not immediately known to the WHERE clause.
select * from
But you can use column alias in the ORDER BY clause because ORDER BY is executed lastly after the entire column list is known.
ORDER BY YEAR
© 2020 Digcode.com. All rights reserved.