You can only use column aliases in GROUP BY, ORDER BY, or HAVING clauses.
Standard SQL does not allow reference to a column alias in a WHERE clause. This restriction is imposed because when the WHERE code is executed, the column value cannot yet be determined.
try it
select payeeid, EXTRACT(WEEKDAY FROM checkdate) as DOW,
(bankcleared - checkdate) as DateDiff
from Master
where (bankcleared is not null) AND ((bankcleared - checkdate)>= 1)
order by payeeid, DOW, DateDiff
For more information, follow these links.
Can you use an alias in the WHERE clause in mysql?
Unknown column in the Where section
source
share