sql - ORA-00904: invalid identifier in subquery (in select clause) -


i have subquery needs use value outer query. fails because of notorious "subquery in oracle can't access value parent query more 2 level deeper" issue.

however, can't figure out how re-write it. examples on web when subquery in clause; mine in select clause.

help anyone?

select  agre.*, agre.orga_ky,         orga.name_la_lb orga_name,          pers.last_name_la_lb signatory_orga__lastname, pers.first_name_la_lb signatory_orga_firstname,         upper(pers.last_name_la_lb) || ' ' || pers.first_name_la_lb signatory_orga_fullname,         -- current agreement orga , compare row find out if row current or expired         case when (             select agre_ky             (                 select a.agre_ky                 t_agreement                 a.orga_ky = agre.orga_ky -- fail!!! ora-00904: invalid identifier                 order a.rec_creation_dt desc             )             rownum = 1         ) = agre.agre_ky 'current' else 'expired' end agreement_status t_agreement agre left outer join t_organization orga on agre.orga_ky = orga.orga_ky left outer join t_person pers on agre.signatory_orga_pers_ky = pers.pers_ky ; 

you can try using row_number window function without sub-query , check if returns expected result.

select  agre.*, agre.orga_ky, orga.name_la_lb orga_name,  pers.last_name_la_lb signatory_orga__lastname, pers.first_name_la_lb signatory_orga_firstname, upper(pers.last_name_la_lb) || ' ' || pers.first_name_la_lb signatory_orga_fullname, -- current agreement orga , compare row find out if row current or expired case when row_number() over(partition agre.orga_ky order agre.rec_creation_dt desc)                            ----------------^^^^^^^^^^^^ change partitioning column per requirement = 1 'current'  else 'expired' end agreement_status t_agreement agre left outer join t_organization orga on agre.orga_ky = orga.orga_ky left outer join t_person pers on agre.signatory_orga_pers_ky = pers.pers_ky 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -