It's my day for steep learning curves and tearing out my hair. I am
experimenting with more complex (well complex for me anyway!!) select
statements.

Can someone explain to me why this fails with the error Unknown column
'DaysLeft' in 'where clause':-

SELECT 
        *,
        TO_DAYS(CONCAT((Year(CURRENT_DATE) + (RIGHT(CURRENT_DATE,5) >
Mid(FROM_UNIXTIME(RegDate + 1728000),6,5))),
                '-',
                Mid(FROM_UNIXTIME(RegDate + 1728000),6,5))) - 
                TO_DAYS(CURRENT_DATE)
AS DaysLeft FROM maintable where DaysLeft<60 and Deleted=0 and
ISNULL(SubOf) OR ActionType=1 ORDER BY DaysLeft ASC;

While this works:-

SELECT 
        *,
        TO_DAYS(CONCAT((Year(CURRENT_DATE) + (RIGHT(CURRENT_DATE,5) >
Mid(FROM_UNIXTIME(RegDate + 1728000),6,5))),
                '-',
                Mid(FROM_UNIXTIME(RegDate + 1728000),6,5))) - 
                TO_DAYS(CURRENT_DATE)
AS DaysLeft FROM maintable where Deleted=0 and ISNULL(SubOf) OR
ActionType=1 ORDER BY DaysLeft ASC;

TIA 

Charlie

Reply via email to