1
Answer

Why I am not able to use a column alias in WHERE clause?

Martin James

Martin James

4y
657
1
I have the following query :
  1. SELECT      
  2.    ID      
  3.    ,CountEmp       
  4.    ,LAG(CountEmp) OVER (ORDER BY DATEAS PREV_NUMBER_OF_EMP      
  5.    ,DATE       
  6. FROM (      
  7.    SELECT * FROM myTab      
  8.    WHERE DATE>=GETDATE()-90      
  9.    ORDER BY DATE DESC      
  10. AS InnerQuery      
  11. WHERE CountEmp <> PREV_NUMBER_OF_EMP    
I am not able to use the PREV_NUMBER_OF_EMP alias.
Answers (1)