nano_nano
nano_nano

Reputation: 12523

Use analytic function result in where clouse

I got this statement:

select ar.*,
LAG(DEST_TIME, 1) OVER (order by FEP_ID) HIT 
from dsyy.archiv ar;

It works pretty fine. now I want to do something like that:

select ar.*,
    LAG(DEST_TIME, 1) OVER (order by FEP_ID) HIT 
    from dsyy.archiv ar 
    where ARR_TIME < HIT;

Unfortunality that is not allowed... Could you tell me how I can deal with the column HIT inside the where-clouse?

Thx a lot

Upvotes: 0

Views: 91

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269763

Simply use a subquery:

select ar.*
from (select ar.*,
             LAG(DEST_TIME, 1) OVER (order by FEP_ID) HIT 
      from dsyy.archiv ar 
     ) ar
where ARR_TIME < HIT;

Upvotes: 3

Related Questions