Looking forward to next rows

hello everybody, i have a particular scenario that i want to solve with a query
here is some sample data. note dates are not sorted in table. i put it here for readabaility reason
WITH table1 AS
  SELECT 111 cid,  To_Date('1/31/2010','mm/dd/yyyy') dt, 'line' line,  345 pid   FROM dual UNION ALL
  SELECT 111 cid,  To_Date('2/1/2010','mm/dd/yyyy') dt,  'line2' line, 346 pid  FROM dual UNION all
  SELECT 111 cid,  To_Date('2/2/2010','mm/dd/yyyy') dt,  'line3' line, 347 pid  FROM dual UNION ALL
  SELECT 111 cid,  To_Date('2/3/2010','mm/dd/yyyy') dt,  'line4' line, 348 pid  FROM dual UNION ALL
  SELECT 111 cid,  To_Date('2/4/2010','mm/dd/yyyy') dt,   null   line, 349 pid FROM dual UNION ALL
  SELECT 111 cid,  To_Date('2/5/2010','mm/dd/yyyy') dt,  'line6' line, 340 pid  FROM dual UNION all
  SELECT 999 cid,  To_Date('2/28/2010','mm/dd/yyyy') dt, 'line7' line, 341 pid  FROM dual UNION ALL
  SELECT 999 cid,  To_Date('3/1/2010','mm/dd/yyyy') dt,  'line8' line, 342 pid  FROM dual UNION ALL
  SELECT 999 cid,  To_Date('3/2/2010','mm/dd/yyyy') dt,  'line9' line, 343 pid  FROM dual UNION ALL
  SELECT 999 cid,  To_Date('3/3/2010','mm/dd/yyyy') dt,  'line0' line, 344 pid FROM dual UNION ALL
  SELECT 999 cid,  To_Date('3/4/2010','mm/dd/yyyy') dt,  'line3' line, 345 pid  FROM dual UNION ALL
  SELECT 999 cid,  To_Date('3/5/2010','mm/dd/yyyy') dt,  'line2' line, 345 pid  FROM dual UNION ALL
  SELECT 444 cid,  To_Date('3/31/2010','mm/dd/yyyy') dt,  'line111' line, 346 pid  FROM dual UNION ALL
  SELECT 444 cid,  To_Date('4/1/2010','mm/dd/yyyy') dt,  'line112' line, 347 pid  FROM dual
SELECT 555 cid,  To_Date('4/2/2010','mm/dd/yyyy') dt,  'line12' line, 247 pid  FROM duali want the following output.
CID     DT            LINE     PID
111     1/31/2010     null     345   --copy line column value from 4th day
111     2/1/2010     line2     346
111     2/2/2010     line3     347
111     2/3/2010     line4     348
111     2/4/2010     null     349
111     2/5/2010     line6     340
999     2/28/2010     line3     341    --copy line column value from 4th day
999     3/1/2010     line8     342
999     3/2/2010     line9     343
999     3/3/2010     line0     344
999     3/4/2010     line3     345
999     3/5/2010     line2     345
444     3/31/2010     line111     346
444     4/1/2010     line112     347
555     4/2/2010     line12     247here is how i get to this output. i want to get all month end dates for a particular id. then i want to look forward and get the values from the 4th day following
the month end date. so for 1/31/2010, the 4th day is 2/4/2010. then i want to get the value from line column in the 4th row and copy that in the current row,
in this case 1/31/2010 line column becomes null since 2/4/2010 has null value
in the case of 444, 3/31 is month end but there is no 4th day to move forward, in this case just display the data.
in the case of 555, there is no month end date so just display the rows for 555 and no need to move forward
i try using last value analytic function but this function will skips row that are null which proceduce invalid result.
if the 4th row we trying to copy from has null values then i want those null values as display in output above.
also i am using oracle 9i 9.2 version and ignore null is not supported.
can someone help me write a query that give above output? thanks alot

Hi,
You're right: repeating basically the same CASE expression 8 (or is it 2 + 8 = 10) times is not a very good idea.
On each row of output, you want 8 columns from some row of the table: possibly the same row, possibly the 4th subsequent row. That sounds like a self-join. Think of joining a "base" row (containing the dt) to a "detail" row of the same table. When dt is the last day of the month, and there are at least 4 later rows, then the detail row will be the 4th later row. In all other cases, the detail row will be the same as the base row.
How can we find the detail row for a given base row? The same way we found the appropriate line value before; only instead of getting tyhe value of line, we need something that will uniquely identify the detail row. If your table has a one-column primary key, you could return that, and use it in the join condition. In the query below, I assume that the combination (cid, dt) uniquely identifies each row.
WITH     got_detail_dt     AS
     SELECT     cid, dt, line, pid
     ,     CASE
              WHEN  dt = LAST_DAY (dt)
              THEN  LEAD ( dt
                          , 4
                      , dt
                      ) OVER ( PARTITION BY  cid
                                      ORDER BY      dt
              ELSE  dt
          END          AS detail_dt
     FROM    table1
SELECT       b.cid
,       b.dt
,       d.line
,       d.pid
FROM       got_detail_dt       b
JOIN       got_detail_dt       d     ON     d.cid     = b.cid
                        AND      d.dt     = b.detail_dt
ORDER BY  cid
,            dt
;Adding more columns to the report is now just a matter of adding more columns to both SELECT clauses. (Depending on what output you will accept, you might make that just the SELECT clause of the sub-query, and use d.* in the main SELECT clause.) At any rate, the addition columns will just be simple column names, not complicated CASE expressions.

Similar Messages

  • Next upcoming expert day Looking forward to the next Expert Day any estimated date of the event

    next upcoming expert day Looking forward to the next Expert Day any estimated date of the event
    it‘s great to be able to post in the forum and obtain help
    my gratitude and appreciation is certainly provided; may I inquire
    as to any estimate Is there another
    Upcoming Expert Day Event
    Since the designated Expert Day is stated as the event has now concluded for
    Expert Day in English (Consumer) - April 18-19, 2012
    Hopefully before September
    Thanks  
    Respectfully

    However if it is Sep I’ll gladly wait and that is still excellent the designated Expert Day’s are great
    my gratitude and appreciation is certainly provided..

  • Looking forward N82's next update

    as a high-end phone specially in camera department they should update few things to produce even better picture like "face detection", "infinitive focus", "brightness". they can easily update these in this sofware version. hope they'll include this & looking forward for N82's next update...
    Nokia N82
    v 31.0.016
    The King of KINGS!

    However if it is Sep I’ll gladly wait and that is still excellent the designated Expert Day’s are great
    my gratitude and appreciation is certainly provided..

  • Next row in JTable (skip disabled rows)

    When I press the down button on my keyboard how can I move to the next available row. It should skip all disabled rows.
    My subclass of JTable looks like this:
    public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
    if (list[rowIndex].isEnabled()) {
    super.changeSelection(rowIndex, columnIndex, toggle, extend);
    All the disabled rows is not selectable. Right now it just stop when the next row is disabled.

    Well, I think the right way to it would be something like..
    public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend)
         // Get to the right row..
         while (!list[rowIndex].isEnabled())
              ++rowIndex;
              rowIndex %= list.length;
         // Change selection to the row found.
         super.changeSelection(rowIndex, columnIndex, toggle, extend);
    The last one is good asuming there must be at least one enabled row, otherwise you should handle this case also...

  • Fiscal date DD-MON and year end looking forward

    Trying to figure out the best way to look forward to the new year and back to the old year when comparing sysdate to a table column fiscal that is formatted DD-MON. The process works perfectly during the year, since is uses current year when comparing data. But at the end of the year, we do not see anything past 12/31 or before 1/1 in a new year. Any ideas? I was thinking of declaring a couple of values and based on sysdate Sep, Oct, Nov, Dec to add 1 year to Fiscal months Jan, Feb, Mar, Apr so they appear as the next year and vice versa for the first months of a new year, subtract one year from the fiscals to indicate previous year. Has anyone worked on something like this in the past?

    Look in to this, i am substituting values for the year, so you will get idea.
    The fisccal date you have is month end all the time or it is all the dates?
    SQL> ed
    Wrote file afiedt.buf
      1  WITH T AS
      2    (SELECT '01-DEC' dt  FROM dual
      3     UNION ALL
      4    SELECT  '05-JUL'   FROM dual
      5     UNION ALL
      6    SELECT  '10-JAN'     FROM dual
      7     UNION ALL
      8    SELECT  '30-MAR'    FROM dual
      9     )
    10  --ens of data
    11  SELECT TO_DATE(dt||'-'||&y,'DD-MON-YYYY') fisc_date,
    12         TO_DATE(dt||'-'||&y,'DD-MON-YYYY')+180 NEW_DATE,
    13      ADD_MONTHS(TO_DATE(dt||'-'||&y,'DD-MON-YYYY'),6)
    14* FROM T
    SQL> /
    Enter value for y: 2008
    old  11: SELECT TO_DATE(dt||'-'||&y,'DD-MON-YYYY') fisc_date,
    new  11: SELECT TO_DATE(dt||'-'||2008,'DD-MON-YYYY') fisc_date,
    Enter value for y: 2008
    old  12:        TO_DATE(dt||'-'||&y,'DD-MON-YYYY')+180 NEW_DATE,
    new  12:        TO_DATE(dt||'-'||2008,'DD-MON-YYYY')+180 NEW_DATE,
    Enter value for y: 2008
    old  13:     ADD_MONTHS(TO_DATE(dt||'-'||&y,'DD-MON-YYYY'),6)
    new  13:     ADD_MONTHS(TO_DATE(dt||'-'||2008,'DD-MON-YYYY'),6)
    FISC_DATE NEW_DATE  ADD_MONTH
    01-DEC-08 30-MAY-09 01-JUN-09
    05-JUL-08 01-JAN-09 05-JAN-09
    10-JAN-08 08-JUL-08 10-JUL-08
    30-MAR-08 26-SEP-08 30-SEP-08

  • Update A Column with value of Column in the next Row

    Hi All,
    I have a table which is like this
    ID NUMBER,
    SUB_ID NUMBER,
    STARTDATE DATE.
    The Value is say for example like this:
    ID     SUB_ID     StartDate
    1     1     1-JAN-09
    1     2     20-FEB-09
    1     3     1-MAR-09
    2     1     10-JAN-09
    2     4     10-APR-09
    2     3     1-MAR-09
    2     2     2-FEB-09
    I have to add a new column END DATE in the table and populate a value which is One Day less than the value of
    start Date for next row. I have to order by ID and SubID and so that colum looks like this.
    ID     SUB_ID     StartDate          END DATE
    1     1     1-JAN-09          19-FEB-09
    1     2     20-FEB-09          28-FEB-09
    1     3     1-MAR-09          DEFAULT-END DATE
    2     1     10-JAN-09          1-FEB-09
    2     2     2-FEB-09          8-Mar-09
    2     3     9-MAR-09          9-APR-09     
    2     4     10-APR-09          DEFAULT END DATE
    Can this be achieved using a single update query or I have ot write a Procedure ...any help will be appreicaited

    or
    merge into test
    using (select rowid rid
                , id
                , sub_id
                , startdate
                , lead (startdate) over (order by id, sub_id) - 1 ed
           from test) x
    on (x.rid = test.rowid)
    when matched then
       update set end_date = x.ed
    ;

  • So whos looking forward to BT speed boost

    SO whos looking forward to BT increasing the speed next year?
    hopefully they wont increase the price much lol
    “I am responsible. Although I may not be able to prevent the worst from happening, I am responsible for my attitude toward the inevitable misfortunes that darken life. Bad things do happen; how I respond to them defines my character and the quality of my life. I can choose to sit in perpetual sadness, immobilized by the gravity of my loss, or I can choose to rise from the pain and treasure the most precious gift I have – life itself.”
    Walter Anderson

    yeah i was talking about the Infinity option 2 (40mb being increased to 80mb)
    “I am responsible. Although I may not be able to prevent the worst from happening, I am responsible for my attitude toward the inevitable misfortunes that darken life. Bad things do happen; how I respond to them defines my character and the quality of my life. I can choose to sit in perpetual sadness, immobilized by the gravity of my loss, or I can choose to rise from the pain and treasure the most precious gift I have – life itself.”
    Walter Anderson

  • Copy a certain row of data into the next row in a same internal table ??

    HI, guys.
    May i know how to copy a certain row of data into the next row in a same internal table ?? Bcz I plan to update a certain colum of data in the row just now into another value..
    For example:-
    *at first...
    ebeln1   ebelp1   xblnr1
    ebeln2   ebelp2   xblnr2
    ebeln3   ebelp3   xblnr3
    *after that, become...
    ebeln1   ebelp1   xblnr1
    ebeln2   ebelp2   xblnr2
    ebeln2   ebelp2   xblnr4
    ebeln2   ebelp2   xblnr5
    ebeln3   ebelp3   xblnr3
    Thanks in advance.

    hi,
    If you have this kind of requirement then you must be having 2 internal tables ,one existing data and 2nd from which you have to insert the records into 1st table.
    so in this case,
    loop at itab1.
      v_index = sy-tabix.
      loop at itab2 into wa where pri_key = itab1-pri_key.
      v_index = v_index + 1.
      insert  wa into itab index v_index.
      endloop.
    endloop.
    Using this code ,your data records similar to your 1st tables primary key records will get inserted into table.

  • I am getting old and looking forward to use I Pad as a Phone if possible through WIFI! I this possible? The screen is to small for me! If possible, with new I Watch taking calls, other uses through I Pad!

    Like I wrote on title, I am getting old and it is not easy to see E-mails, news etc. on a I phone! New I phone will not help me for the size.
    If possible, everything without calls, I would like to use I Pad as direct unit, and for calls through I Pad over WIFI all calls. If a call as Skype, I would like
    to use the I Pad as a monitor. Is this possible?
    I found on a side that there is a product for people for better hearing, which can be put into the ears, using WIFI with I Phone.
    If this product could be used also for I Pad as a Phone for hearing, and the I watch or I Pad as Microphone, it will be great for old Mac users.
    Is this possible with our system know?
    I am using Mac since Classic II! Would like to continue with the newest items with the possibility for old person with bad Eyes or Ears.
    Looking forward for a kind answer
    with regards
    Christian an old Mac user!

    Definitely No

  • How to set the current row in table automatically when tabout from one row to next row

    Hi
    I'm using jdev 11.1.2.0.0
    How can we set the  row(in which row focus is)  as current row in the table?
    If we create a table with single row selection, then whichever row we select, that row becomes current row because of the selection listener(#{bindings.xxvo.collectionModel.makeCurrent}).
    Then if we do tabout from one component to another component in table and moved to next row, then the focus would be on another row .
    when focus is shifted from one row to another row, then how can we make the focused row as current row or selected row.
    Any suggestion would we appreciated
    Thanks.

    Add clientListener inside table component and set client listener type to dblClick with method as a JavaScript method name.
    <af:clientListener method="dblclk" type="dblClick"/>

  • How can I use a SCH-LC11 device in CHINA which bought from ebay. I am not Verizon customer but I prefer to using your 4G LTE Router . How can I get the unlock code? The device may have a bad ESN but I only use it in CHINA. Kindly looking forward your repl

    How can I use a SCH-LC11 device in CHINA which bought from ebay. I am not Verizon customer but I prefer to using your 4G LTE Router . How can I get the unlock code? The device may have a bad ESN but I only use it in CHINA. Kindly looking forward your reply. Thanks!

    It's good to read Antoniad's post.  It reassures me that I can use my new iPad as an international communication device which is the reason I purchased the thing.  However, I called Verizon today (my provider of cellular data) who told me that I can't just pop in a SIM card as you suggested.  He also said that he was from the "Pre-Pay" division of Verizon and he was certain that I couldn't do what I planned to do.  I was extremely disappointed as I had called Apple prior to buying the iPad and I read the algorhythm on the website for choosing an iPad before purchasing.  Those sources were quite specific and the information seemed clear.  I would be able to use my iPad to communicate through cellular connections while traveling on the road, literally, abroad.  I was told that I could pop in a data card wherever I was, just as you indicated in your message above, and voila I was good to go.  The Verizon rep definitively rained on that parade, but said that I might be able to do this if I have a "Post-Pay" account, a different area of Verizon.  I haven't had the chance to talk to this division yet, so I looked to Apple's Support for answers.  Maybe I will find out that I can use my iPad as an international communication device while traveling on the road afterall, however, it appears I may need a different type of account (Post-Pay), something I was never warned about. Can I switch to this kind of account?  I don't know.  I have to find out.  If you have any information about this issue, it would be good to share since I strongly suspect there are others who bought the iPad for the same purpose that I have.

  • Create row as next row on click of add another row button not on top of it

    My af:table is based on a transientVO (all the attributes are transient)
    This is just for data entry and not for data retrieval
    So i have placed add another row button on my af:table
    After i enter data in the first row and click add another row button the data is being moved to second row and the new row is created on top of that
    I want the row to be created as next row . not on top of my existing row
    How can we do this

    would this help you:
    http://lucbors.blogspot.com/2010/12/adf-11g-how-to-control-where-new-row-is.html

  • I downloaded Safari 5.1 onto Mac OS 10.6.8 some time ago.  Yesterday the back/forward arrows next to the url window changed to a  , which adds the current url as a bookmark.  I want the arrows back.  What happened, and how can I fix this?  Thanks.  kammro

    I downloaded Safari 5.1 onto Mac OS 10.6.8 some time ago.  Yesterday the back/forward arrows next to the url window changed to a +, which adds the current url as a bookmark.  I want the arrows back.  What happened, and how can I fix this?  Thanks.  kammro

    There's another way.
    Right or control click the + then click Remove Item.
    Just remembered that keyboard shortcut!
    You're welcome 

  • Can I use action build to fade one table row as I move to the next row in the table?

    I have built a table with 6 rows.  Right now,I am building the table row by row when I play the slide. Is there a way to fade or dissolve one row when I move to the next row in the table? I want to be able to de-emphasize the row I just discussed when I move to the next row in the table. I can fade the entire table by invoking that action but I do not seem to be able to use this action one row at a time. Thanks for your comments and assistance.

    you will have to use a workaround to get the exact effect you described
    create a table with out any text
    use text tool to add text and position in each table cell
    select the text boxes( command click) in the first row and group them (arrange > group)
    use a, build in, to display text and then a, build out, to remove it
    repeat the above for the other rows

  • Sales and purchase journal - balance carry forward to next page

    Hi all,
    When we run sales and purchase journals in transaction S_ALR_87012357 (Belgium) and print it we want a summary per page and balance carry forward to next page.
    The paging is correct by selecting "statistical info not printed" in output control but we don´t want only summary on last page, instead on every page and a total summary on last page.
    Does anyone knows how to mangage this?
    Best regards Lisa

    With a developer implement a the BADI  FI_TAX_BADI_010

Maybe you are looking for

  • Acrobat 9 Killed Acrobat 8 and cannot go back to 8 even if uninstalled is done

    Acrobat 9 Killed Acrobat 8 and cannot go back to 8 even if uninstalled is done, Got 8 back on but the updates for Acrobat will not install. The other CS3 products work fine, they have applied their update but Acrobat keeps failing. The message in my

  • Flash CS4 crashes as soon as a new file is created. ???

    For context: I just installed Snow Leopard on my Macbook Pro (2007 model) and thus just recently installed CS4 Design Premium Student Ed. Below is what came up as the result of the crash. Process:         Adobe Flash CS4 [2255] Path:            /Appl

  • Pictures are missing

    I have recently noticed that all my pictures disappeared from my phone.  When I take new pictures I select save but when I want to view the pics afterwards they are not there. When I go to WhatsApp and select to send a picture from this application,

  • Opening mov files - weird color patterns + freeze

    Hi, Suddenly when opening mov files, quicktime shows weird colors instead of a video. It also takes a long time to open, and quicktime then hangs. I don't know what I installed that could have caused the problem. I tried reinstalling but that doesn't

  • Non-Deployed Applications in OSD Task Sequence Are Deployed To Collection Members where OSD TS is deployed

    Hello, I have a situation where an application (which is not deployed) that is part of an OSD Task Sequence is being deployed to computers that are in the same collection my TS for OSD is deployed. For OSD I have created an application to check the B