You can't reference it that way; either use this
SELECT name_,
client_p AS client,
TO_DATE (first_date) - TO_DATE (LAST_DAY) AS difference
FROM table1.mydata
WHERE TO_DATE (first_date) - TO_DATE (LAST_DAY) > 50;
or - with your query as a CTE (or a subquery):
WITH
temp
AS
(SELECT name_,
client_p AS client,
TO_DATE (first_date) - TO_DATE (LAST_DAY) AS difference
FROM table1.mydata)
SELECT *
FROM temp
WHERE difference > 50;
Note that you should store dates as DATE
s, not strings - which is what TO_DATE
function suggests.
But, if you do store them as strings, then you should provide format model to the TO_DATE
function. It is unknown which format you do have, but - you should know it.
On the other hand, if you store dates as you should (in DATE
datatype columns), then remove TO_DATE
from your query.