Martin James

Martin James

  • 2k
  • 96
  • 3.1k

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

Mar 26 2021 9:41 AM
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)