Re: Merge Statement
Date: Tue, 3 Feb 2009 05:59:22 -0800 (PST)
On Feb 2, 3:12 pm, ddf <orat..._at_msn.com> wrote:
> On Feb 2, 2:06 pm, Mtek <m..._at_mtekusa.com> wrote:
> > I have this merge statement:
> > MERGE INTO rank_history_new zrh
> > USING (SELECT v_id AS new_m_ticker, v_rec.z_rank_d AS new_rank
> > FROM dual) zrh2
> > ON (zrh.m_id = v_id AND rank = v_rec.z_rank_d)
> > WHEN NOT MATCHED THEN
> > INSERT (m_id, rank, time, add_del_flag)
> > VALUES (v_id, v_rec.z_rank_d, v_rank_date, v_add_del_flag);
> > It does not work 100%. Actually what I want is to compare it with the
> > LAST entry for the v_id. So, if I have the following. So if there
> > are 4 entries for a given ID, I want to compare it against the last
> > entry.
In this case, rank_history_new has several records for each ID. There is also a DATE on those records. When performing the MERGE, I want to compare against the record with the MAX date for that ID.
A 6/3/08 A 9/7/08 A 1/5/09 <-- Use this one in the MERGE statement.
So again, back to the merge statement, I am comparing 'rank' values, but I want to perform that compare on the record with the MAX date for that ID.
Does this help a bit in my explanation? Received on Tue Feb 03 2009 - 07:59:22 CST