Code block:
update yrb_purchase px
set px.club = (select club
from (select p.title, p.year, o.club, o.price,
ROW_NUMBER() OVER(PARTITION BY p.title, p.year
ORDER BY o.price
) rn
from yrb_purchase
inner join yrb_offer o on p.title = o.title
and p.year = o.year
inner join yrb_member m on m.club = o.club
inner join yrb_customer c on c.cid = p.cid
and c.cid = m.cid
where p.cid = px.cid
and p.title = px.title
and p.year = px.year
order by title
)
where rn = 1
)
where ....
My issue is thus: upon execution of the above code, I get 'SQL0204N "PX.YEAR" is an undefined name. SQLSTATE=42704'. I was under the impression that in this case, the row being looked at by update would be passed into the inner query. What have I done wrong? The example I was given was:
update yrb_purchase P
set club = (
select min(M.club)
from yrb_member M, yrb_offer O
where P.cid = M.cid
and M.club = O.club
and P.title = O.title
and P.year = O.year
)
where
club <> (
select min(M.club)
from yrb_member M, yrb_offer O
where P.cid = M.cid
and M.club = O.club
and P.title = O.title
and P.year = O.year
);
which was given as an example of bad code, but code that should work nonetheless.