How to check the previous records on a select

I have a query that returns the data as follows
COL1     COL2     WK_DATE     INDICATOR
2     2     01/16/2010     A
0     0     01/16/2010     
0     0     01/16/2010     
1     1     11/06/2010     B
0     0     11/06/2010     
0     0     11/06/2010     
1     1     11/20/2010     C
0     0     11/20/2010     
0     0     11/20/2010     
2     2     05/12/2012     C
2     2     05/12/2012     A
3     3     05/12/2012     B
But the data set is incomplete, as I could not fill indicator on null values
Could you please let me know the service which will be useful for this condition

ALL I NEED IS JUST TO BRING THE ABSENT ON THAT PARTICULAR DATE INDICATOR

The expected output is
COL1     COL2     WK_DATE     INDICATOR
2     2     01/16/2010     A
0     0     01/16/2010     B
0     0     01/16/2010     B
1     1     11/06/2010     B
0     0     11/06/2010     A
0     0     11/06/2010     C
1     1     11/20/2010     C
0     0     11/20/2010     B
0     0     11/20/2010     A
2     2     05/12/2012     C
2     2     05/12/2012     A
3     3     05/12/2012     B
Thank you

user12236189 wrote:
Thanks, I got it lag and partition by with a nested query

There is no need of LAG. Just change the nested table:

select  nvl(b.COL1,0) as COL1,
        nvl(b.COL2,0) as COL2,
        b.WK_DATE,
        a.Column_Value Indicator
  from      table(sys.odciVarchar2List('A','B','C')) a
        Left Join
            (
             select  COL1,
                     COL2,
                     WK_DATE,
                     Indicator
               from  data_table
            ) b
          partition by (b.WK_DATE)
          on (b.Indicator = a.Column_Value)
  order by b.WK_DATE,
           b.Indicator,
           a.Column_Value
/

Now:

SQL> with data_table as (
  2                      select 2 col1,2 col2,to_date('01/16/2010','mm/dd/yyyy') wk_date,'A' indicator from dual union all
  3                      select 1,1,to_date('11/06/2010','mm/dd/yyyy'),'B' from dual union all
  4                      select 1,1,to_date('11/20/2010','mm/dd/yyyy'),'C' from dual union all
  5                      select 2,2,to_date('05/12/2012','mm/dd/yyyy'),'C' from dual union all
  6                      select 2,2,to_date('05/12/2012','mm/dd/yyyy'),'A' from dual union all
  7                      select 3,3,to_date('05/12/2012','mm/dd/yyyy'),'B' from dual
  8                     )
  9  select  nvl(b.COL1,0) as COL1,
 10          nvl(b.COL2,0) as COL2,
 11          b.WK_DATE,
 12          a.Column_Value Indicator
 13    from      table(sys.odciVarchar2List('A','B','C')) a
 14          Left Join
 15              (
 16               select  COL1,
 17                       COL2,
 18                       WK_DATE,
 19                       Indicator
 20                 from  data_table
 21              ) b
 22            partition by (b.WK_DATE)
 23            on (b.Indicator = a.Column_Value)
 24    order by b.WK_DATE,
 25             b.Indicator,
 26             a.Column_Value
 27  /

      COL1       COL2 WK_DATE   INDICATOR
---------- ---------- --------- ----------
         2          2 16-JAN-10 A
         0          0 16-JAN-10 B
         0          0 16-JAN-10 C
         1          1 06-NOV-10 B
         0          0 06-NOV-10 A
         0          0 06-NOV-10 C
         1          1 20-NOV-10 C
         0          0 20-NOV-10 A
         0          0 20-NOV-10 B
         2          2 12-MAY-12 A
         3          3 12-MAY-12 B

      COL1       COL2 WK_DATE   INDICATOR
---------- ---------- --------- ----------
         2          2 12-MAY-12 C

12 rows selected.

SQL> 

SY.

Tags: Database

Similar Questions

  • How to check the previous value of the element in a multi-record block

    Oracle Version: 10 g
    Forms Version: 10 g

    Hi all
    Hello everyone, I have a multi-dossier block in a form where one of the values of elements is of LOV.user can select the value of LOV.

    If once the user selects the value of LOV and moves to the next of the multi-file record, and selects the value of LOV again, I shouldn't allow users to select the previous value of the user in order to avoid duplication of records.

    and important remark is that I should get there before you save it in the database because once registered in the database I can compare the values and hide the previous value.


    Any help will be appreciated.


    Thanks and greetings

    This is a question frequently asked in the forum! There are several different solutions. Take a look at the following articles. Both will perform the necessary verification of duplicates.
    Forms - registration of treatment group (value in double check...
    or
    Avoid records duplicated in a block

    If none of these solutions don't work for you, search the forum for other options.

    Hope this helps,
    Craig B-)

    If someone useful or appropriate, please mark accordingly.

  • Conditional looping. How to check the previous result s of closure?

    Hello

    I would like to repeat a sequence for the second time if the sequence is not the first time. To do this, I would use the loopback step properties feature. Question: How can I build the loop State Expression referring to the step of Staus (pass/fail) of the first loop?

    In loopback loop Type properties, select number of pass/fail.  Then assign the stop after 1 and iterations to pass.  You can set the maximum number of iterations to any value you want (in your case, it sounds like 2).  You can play with the numbers to fit your scenario.  As you play with the numbers, you'll see the values of the changing expressions.

    I could give you a better answer if I understand exactly what you wanted but it will probably do what you want.

  • trigger check the previous record of line before insert/update

    Hi all

    I would like to create a trigger that a customer will not be able to create a new account, if it has a status of "Non-payment".

    CustomerID custNRIC paymentStatus

    ----------------------------------------------------------------

    Non-payment of 200 F7654323A

    It will reject the following statement.

    insert into customer (custID, custNRIC, paymentStatus) VALUES (201, 'F7654323A', 'Good');

    so, how can I go around to solve this issue?

    sqlnoob wrote:

    Hi all

    I would like to create a trigger that a customer won't be able to create a new account, if it has a "Non-payment" statusYou

    You can't do things like that in a trigger.

    It will reject the following statement.

    insert into customer (custID, custNRIC, paymentStatus) VALUES (201, 'F7654323A', 'Good');

    The trigger would dismiss as EVERY other row in the same transaction, if you try to use a trigger.

    You can't stop a trigger to run except by raising an exception and the trigger stop from doing anything for ANY line that the trigger activated on.

    together to define

    CREATE OR REPLACE TRIGGER reject_new_account

    AFTER INSERT OR update ON the client

    FOR EACH LINE

    DECLARE

    PRAGMA AUTONOMOUS_TRANSACTION;

    totover NUMBER (3);

    BEGIN

    SELECT COUNT (*)

    IN totover

    OF THE customer

    WHERE: NEW.nric = customer.nric

    AND: NEW.badstatus = "Non-payment";

    Why are you tring to use an autonomous transaction? All that makes the transaction will NOT be part of the transaction that fired the trigger.

    I know there is a problem with the line 13 ' AND: NEW.badstatus = "Non-payment".»

    so, how can I go around to solve this issue?

    This is the LEAST of your problems. Do NOT try to nontransactional things in a trigger.

    Also, don't try to query the table that the trigger is activated on.

    This is the fundamental question: Oracle is a multi-user system. Other users may be perform DML on the same table at the same time. So any NUMBER that provides this trigger can turn out to be inaccurate when other users post their transactions.

    The best you can do in a trigger is throw an exception. If you do this will affect the complete relaxation and all the lines he treated - not only one line you see that you want to reject.

    A requirement like yours needs to be satisfied by the presence of DML performed using functions or procedures and serialize the customer INSERT/update this transaction that a SINGLE session/user/can perform DML on the table for a client given.

  • How to get the previous record that meets a criterion?

    Hello!

    I am trying to create a query that adds information which finally fixed an element for a given 'pause'.

    I have a table, let's call it actionHistory, which looks like:

    ID | timestamp | action | author
    ------------------------------------------------
    101477 | 2010-05-10 09:10:20 | Difficulty | Tim
    101477 | 2010-05-10 09:10:30 | change | John
    101477 | 2010-05-10 09:10:40 | breaking | Maggie
    101477 | 2010-05-10 09:10:50 | Difficulty | Rick
    222222 | 2010-05-10 09:10:30 | change | Lewis
    222222 | 2010-05-11 09:10:40 | breaking | Maggie
    222222 | 2010-05-11 09:10:50 | Difficulty | Tim
    222222 | 2010-05-12 09:10:40 | Difficulty | Maggie
    222222 | 2010-05-13 09:10:40 | breaking | Albert

    I'm looking for is the following result:

    ID | timestamp | action | author | lastFixBy
    -----------------------------------------------------------
    101477 | 2010-05-10 09:10:20 | Difficulty | Tim |
    101477 | 2010-05-10 09:10:30 | change | John |
    101477 | 2010-05-10 09:10:40 | breaking | Maggie | Tim
    101477 | 2010-05-10 09:10:50 | Difficulty | Rick |
    222222 | 2010-05-10 09:10:30 | change | Lewis |
    222222 | 2010-05-11 09:10:40 | breaking | Maggie |
    222222 | 2010-05-11 09:10:50 | Difficulty | Tim |
    222222 | 2010-05-12 09:10:40 | Difficulty | Maggie |
    222222 | 2010-05-13 09:10:40 | breaking | Albert | Maggie

    Can you tell me how I can make?
    I tried many ways but no return to what I'm looking for.

    Thanks in advance.

    Published by: user8910765 on June 5, 2010 13:51

    Published by: user8910765 on June 5, 2010 14:00

    Hello

    That's what you asked for in Oracle 10:

    SELECT       a.*
    ,       CASE
               WHEN  action = 'break'
               THEN  LAST_VALUE ( CASE
                                    WHEN  action = 'fix'
                                    THEN  author
                                   END
                                   IGNORE NULLS
                               ) OVER ( PARTITION BY  id
                                               ORDER BY      tmstmp
                                    )
           END        AS lastfixby
    FROM       actionhistory         a
    ORDER BY  id
    ,            tmstmp
    ;
    

    Like all of the built-in functions, LAST_VALUE is documented in the manual of the SQL language:
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions073.htm#sthref1508

    user8910765 wrote:
    ... just in case where it might be useful, one of the queries I've tried myself a left subquery joined that Oracle has no right ("a column may be outside not attached to a subquery').

    Much more, it would help if you posted the request.
    It looks like you were using the old outer join notation (+). You can get the desired results by using an outer join with ANSI rating, but I think it would be more complicated and slower than with a LAST_VALUE.

  • How to check the values in multi-record block. ?

    Hello

    I'm new to forms. I have the field titled "Comments" in the block of multi-record. I have a button called "reject". Reject button is in the control block. If I press the button reject, field comments must be entered in one of the record. Otherwise, he should tell message. How to check the multi-record block. ?

    Pl.Help.

    Thanks in advance.
    Mano

    Mano,

    Add NEXT_RECORD just before the END of the LOOP.

         GO_BLOCK('');
         FIRST_RECORD;
         LOOP
              IF NVL(:., ' ' ) = ' ' THEN
                   MESSAGE('');
                   RAISE FORMS_TRIGGER_FAILURE;
              END IF;
              EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE';
              NEXT_RECORD;
         END LOOP;
    

    Kind regards

    Manu.

    If my response or response from another person was helpful, please mark accordingly

  • Navigate the previous record, next record by entering the key in place and key press

    Hello

    JDeveloper11g_

    I am trying to solve how to navigate the previous record, then register by entering the key in place and key press to the table of the ADF.
    If any of you have this solution by JScript of Backing Bean please help me.

    Thank you
    Zed
    ===

    Hi Zaza,

    Try tweaking the Javascript code, as shown below.

    /** Change this line below .... **/
    var newStr = id.replace(/:\d:/, ':' + numValue + ':');
    
    /** ... to this... **/
    var newStr = id.replace(/:\d+:/, ':' + numValue + ':');
    

    Kind regards
    Amélie Chan

  • How to install the previous version of sound recorder for windows - the windows sound recorder 7 isn't good

    How to install the previous version of sound recorder for windows - the windows sound recorder 7 isn't good

    Hi Harold,.

    Which is exactly the problem that you are facing with the sound recorder in Windows 7?

    You will not be able to downgrade the version of sound recorder for Windows in Windows 7.

    To learn more about sound recorder in Windows 7, see this link:

    http://Windows.Microsoft.com/en-in/Windows7/record-audio-with-sound-recorder

    To fix the fundamental problems with the tape recorder for Windows 7, see:

    http://Windows.Microsoft.com/en-in/Windows7/open-the-recording-audio-Troubleshooter

    Let us know if it helps.

    Thank you.

  • How I've hidden the elements after the query when moving back to the previous record

    Hello world

    I create a form with the developer 6i and I use set_item_property(item_name,visivile,...), in post_change, in when_list_change relaxation too

    to hidden and activate certain elements.

    When I enter the data, everything works fine, when I do a request for enforcement to the data set and move to the next record every thing works fine, but

    When I want to go back to the previous record, the two triggers does not,

    could someone tell me where to put this code, so it can walk perfecty when I move to the next record or previous record

    best regards;

    You can use one - news - when? -Instance triggers (where? = point, Record, block, etc.).

    Craig...

  • How to check the manufacturing date of the Z2?

    Hello, so the title sums up pretty much everything this. On the previous xperia phones, you can check under the battery, with xperia Z, that it was written on the back at the bottom but on Z2? How to check the date of manufacture?

    Hello and welcome to the community! Since you are new, please make sure that you have checked our Forum.

    This label can be found in the MicroSD slot, click on the following link:
    http://Userguide.sonymobile.com/referrer.php?region=en&product=Xperia-Z2#IMEI-number.html

  • Getting value of an element in the previous record in a table

    Good afternoon

    I'll try to explain my problem:

    I have a block table points X, Y and Z (all are elements of database)...

    On the first record, the user is required to set the values for all the elements...

    For the rest of the records, the value of X must be the value of Z in the previous record.

    How I could do and what is the best way to do it?

    Thanks in advance.

    Daniel Guzzo

    OK, problem solved by myself:

    IF: System. CURSOR_RECORD! = 1 and: global .rec_changed = 0 THEN

    : global .rec_changed: = 1;

    PREVIOUS_RECORD;

    : global .fec_hasta: = to_char(:cret_prod_pol_renovacionesb.crpn_fe_hasta,'DD-MM-YYYY');

    NEXT_RECORD;

    : global .rec_changed: = 0;

    IF: global.fec_hasta is null THEN previous_record; end if;

    : cret_prod_pol_renovacionesb.crpn_fe_efectiva: = to_date(:global.fec_hasta,'DD-MM-YYYY');

    -MESSAGE(:global.fec_hasta);

    END IF;

    If anyone has a better solution, it will be welcome.

    Thank you

  • Records of paint according to the previous record

    Hi all

    I need a bitch the foreground color of a record by a field in the previous record, I mean, if the current record contains the same data as the previous it should be blue, but it is different to be red.

    can anyone tell me how and in which trigger.

    THX!

    In addition Francis... If you block based on SQL query you can use the functions of LAG and LEAD in your SQL to get the previous values in the same line.

  • Anyone know how to check the date of warranty until when?

    Anyone know how to check the date of warranty until when?

    https://checkcoverage.Apple.com/Jo/en/;JSESSIONID=9pJ0X9pFPJtNg3c44yDGCvk9pVpt5l QSgn4B60y4Skv1WfmnqMkF!-1840326800

  • How to check the balance on the gift card itunes

    How to check the balance on the gift card itunes

    Redeem it

  • Satellite A200 - how to check the temperature of the processor fan?

    Hi all

    I have a Satellite A200 that my teenagers use a little, or abuse a little! Recently, it would not start up. I suspect the fan and pulled out the fan cleaned and tested the fan on a PSU, worked out well. He put it back together, ran startup repair and now the computer is operating normally. The fan is however not appear to come at all. In the Device Manager it tells me it works very well. I'm all good with the mechanical side of the House, but I'm a quamby operating system! How to check the temp CPU or fan?

    Thought that replace the fan but don't want to go that far just to get no results. Currently using the vacuum on low like an external fan and didn't want to just run the laptop with no cooling for fear of permanent damage. Although children watch movies with her on their doona may have already reached this!

    Any advice would be appreciated.

    Hey mate,

    How to clean the fan exactly? It s advisable to use the jet of compressed air. This could blow the dust of fans cooling and, therefore, it of not necessary to disassemble the laptop.

    In addition if the fan doesn't work anymore it of necessary to replace. You can order spare parts at an authorized service provider.

Maybe you are looking for

  • Laptop HP 15-ac153ca: pregnant with a fuzzy noise?

    My laptop makes a noise all blurry and weird. When I turn on a video and it's blurred, I go to the 'Search and solve problems with the devices' thing and let it scan my laptop. He will say that he had no problems found and then all of a sudden the au

  • Several questions on Portege R500

    I got this new Portege R500 (PPR50E) and the fan noise is driving me crazy! I can't believe why the processor should run all the time so warm, even if it isn't on the heavy load. Even online light surf starts the fan of rolling and moaning of it are

  • Satellite C650 - 18 d - it comes to screen or a computer?

    Hello could someone help and tell me if there is a problem with the screen or computer.If screen, is it easily fixed with a replacement screen? or something more complicated. Thank youHP [flickr photo | http://www.flickr.com/photos/79882183@N06/]?

  • HP laptop: where can I find the windows 10 product key for my Hp laptop I have moved and can not find my disk

    I need help to locate the windows product key 10 to my Hp laptop I lost the box and disc as I have recently moved and cannot locate I look under the battery and does not see the key code. My son decided to factory reset my laptop.

  • Table 2d-Fibonacci

    I was looking through the files of workshop here: https://decibel.NI.com/content/servlet/JiveServlet/download/21043-3-43168/Fibonacci.VI I try to edit this file to make it a 2d array. So if I try to add the dimension to the one marked "continuation o