Get only one record for an id for a date if multiple record exists

Hi,
I need help with below mentioned scenario.
DB Version: 11.2.0.3.0.
Requirement:
Fetch account records that were created after last run of program
Get latest record for an account on a given date if there are multiple records for same account.
If there is a gap of more than 1 day from last run of program, then get latest record for an account for each date if there are multiple records for same account.
Create table t_test
  Id           number not null,
  cust_id      number not null,
  cust_Acct_id number not null,
  ins_date     date   not null
insert into t_test values
(1, 12345, 678905, to_date('05/31/2012 12:05:10 PM','MM/DD/YYYY HH:MI:SS PM'));
insert into t_test values
(2, 12345, 678905, to_date('05/31/2012 05:25:46 PM','MM/DD/YYYY HH:MI:SS PM'));
insert into t_test values
(3, 12345, 678905, to_date('05/31/2012 11:48:00 PM','MM/DD/YYYY HH:MI:SS PM'));
insert into t_test values
(4, 12345, 678905, to_date('06/01/2012 12:05:10 PM','MM/DD/YYYY HH:MI:SS PM'));
insert into t_test values
(5, 12345, 678905, to_date('06/01/2012 05:25:46 PM','MM/DD/YYYY HH:MI:SS PM'));
insert into t_test values
(6, 12345, 678905, to_date('06/01/2012 11:48:00 PM','MM/DD/YYYY HH:MI:SS PM'));
insert into t_test values
(7, 12345, 678905, to_date('06/02/2012 12:05:10 PM','MM/DD/YYYY HH:MI:SS PM'));
insert into t_test values
(8, 12345, 678905, to_date('06/02/2012 05:25:46 PM','MM/DD/YYYY HH:MI:SS PM'));
insert into t_test values
(9, 12345, 678905, to_date('06/02/2012 11:48:00 PM','MM/DD/YYYY HH:MI:SS PM'));
create table t_log
  id            number not null,
  prgrm_id      number not null,
  last_run_date date   not null
insert into t_log values
(1,1009,to_date('5/30/2012 07:05:12 AM','MM/DD/YYYY HH:MI:SS PM'));Result required:
id cust_id cust_acct_id ins_date
3 12345 678905 '05/31/2012 11:48:00 PM'
6 12345 678905 '06/01/2012 11:48:00 PM'
9 12345 678905 '06/02/2012 11:48:00 PM'
I tried below sql but it will return only id 9 record.
select
    id,
    cust_id,
    cust_acct_id,
    ins_date
from
    select
        id,
        cust_id,
        cust_acct_id,
        ins_date,
        row_number() over (partition by cust_acct_id order by ins_date desc) rn
    from
        t_test t
    where
        t.ins_date > (
                      select
                          last_run_date
                      from
                          t_log l
                      where
                          l.prgrm_id = 1009
where rn = 1;Thanks in advance.

Try:
SQL> select
  2      id,
  3      cust_id,
  4      cust_acct_id,
  5      ins_date
  6  from
  7      (   
  8      select
  9          t.id,
10          t.cust_id,
11          t.cust_acct_id,
12          t.ins_date,
13          row_number() over (partition by cust_acct_id, trunc(ins_date) order by ins_date desc) r
n
14      from
15          t_test t
16      ,   t_log l 
17      where
18          t.ins_date >= l.last_run_date
19      and l.prgrm_id = 1009
20      )
21  where rn = 1;
        ID    CUST_ID CUST_ACCT_ID INS_DATE
         3      12345       678905 31-05-2012 23:48:00
         6      12345       678905 01-06-2012 23:48:00
         9      12345       678905 02-06-2012 23:48:00But I now see that Bob already nailed it, while I was testing it ;)

Similar Messages

  • Allow only one set of parameter values for all worksheets

    I would like to " Allow only one set of parameter values for all worksheets ", but prompt before executing the worksheet. This function is a great time saver, but the users on occasion would like to change at the least one of the parameters. Is this possible? What setting do I use? I've tried various combinations of the " After opening a workbook: " on the options page. " Run query automatically", " Don't run query (leave sheet empty) ", and " Ask for comformation ". I would have thought that "Ask for comformation " was the trick, but no. I'm considering putting a do nothing parameter that has the setting of " Allow different parameter values for each worksheet. " so that it will keep all the others, default this one, but prompt for a possible change.
    Any thoughts...
    Thanks,
    Jamie

    Hi Jamie
    Even though you have the same parameter for all worksheets a user can still choose what to use on a worksheet. Its just that if they click to another worksheet then that parameter will be applied.
    Which version of Discoverer are you using?
    Best wishes
    Michael

  • How to get only one character

    my problem is the following:
    i want to get only ONE character from the input without pressing the "enter"-key. for example pressing ESC and doing something because it is ESC hit.
    thank you

    You can't. Either use a GUI or create a JNI DLL function that calls getch ().
    Kind regards,
      Levi

  • I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page word document, some recipients get only one page.  Also sometimes when I burn an image from iPhoto on to a disc, only part of the image appears.  Why?

    I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page Word document by email, some recipients get only one page.  Also when burning an image from iPhoto (usually no larger than 1mb) on to a disc, only part of it appears.  It appears to have been magnified so that only a part of the image appears.  Can anyone enlighten me as to what is happening?  And how to fix it??

    I have Office 2011 which includes Word.  Ever since downloading Mavericks, when I try to send a two-page Word document by email, some recipients get only one page.  Also when burning an image from iPhoto (usually no larger than 1mb) on to a disc, only part of it appears.  It appears to have been magnified so that only a part of the image appears.  Can anyone enlighten me as to what is happening?  And how to fix it??

  • Only one Extractor source is allowed in a data flow ?

    Hi,
    We have a common scenario (I think this is common for SAP ECC in general) where we have 2 tables, *_ATTR (Attributes) and *_TEXT (descriptions).  We extract these using extractors.
    Initially when we tried to place 2 in a dataflow, we got an error saying 'Only one Extractor source is allowed in a data flow'.
    To work around this, we created 2 embedded dataflows and everything seems to work fine.  But when I do a validate all, I get the error:
    [Data Flow:DF_ODS_MD_WBS_ELEMENT]  Only one Extractor source is allowed in a data flow. (BODI-1116145)
    Should I be worried ?  My gut feeling is this is a bug in the validate all function, but I could be wrong.  Everything seems to run fine, so is it safe to ignore this ?
    This currently effects about 5 dataflows, but we have about 40 more to implement like this, so I don't want to get it wrong.
    Thanks,
    Leigh.

    Like it says, that is invalid xml. It looks like it is a bug
    in the example doc.
    Add a root node to the xml and you should be ok.
    Tracy

  • Get only one row for each kind of a column

    hi there!
    i have a little problem.
    I have a table with 10 columns. One of them has repeated values. My goal is to get all the rows with this column only one time for each values that it has.
    Ex:
    Col1 Col2 Col3
    A A A
    B B B
    C A C
    D C D
    Column 2 has repeated values. My goal is to get:
    A A A
    B B B
    D C D
    Only one time each value of column 2.
    Thanks guys! ;)

    SQL>  CREATE TABLE Tbl (col1 VARCHAR2(1),col2 VARCHAR2(1),col3 VARCHAR2(1));
    Table created.
    SQL> INSERT INTO Tbl VALUES ('A','A','A');
    1 row created.
    SQL>              INSERT INTO Tbl VALUES ('B','B','B');
    1 row created.
    SQL>              INSERT INTO Tbl VALUES ('C','A','C');
    1 row created.
    SQL>              INSERT INTO Tbl VALUES ('D','C','D');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> SELECT * FROM tbl t1
      2  WHERE
      3  rowid=(SELECT min(rowid)
      4         FROM tbl t2
      5         WHERE t1.col2=t2.col2);
    C C C
    A A A
    B B B
    D C D
    SQL> SELECT * FROM tbl t1
      2  WHERE
      3  rowid=(SELECT max(rowid)
      4         FROM tbl t2
      5         WHERE t1.col2=t2.col2);
    C C C
    B B B
    C A C
    D C DEdited by: Saubhik on Aug 3, 2010 1:31 AM

  • Is it fair to pay for one year service and get only one trial?

    Why am I only allowed to convert one file from PDF to Word when I have paid a whole year's subscription (US$19.99) to do just that?

    OK, So after waiting on hold on the phone for an hour and getting mad I got ahold of someone here on live chat and got disconnected but have an answer for everyone and a solution! Here it is so you don't have to go through the same thing,
    It takes 24-48 hours for your payment to clear in order for you to be able to use the program. (I told them it should clearly state this on there)
    Then I asked if there was a way to get one or two more conversions for now and was told to use the 30 day FREE trial version of "Acrobat XI Pro" I was told by adobe customer service just now that this has the same thing included in it.
    So if you only needed it temporarily you can get a full refund for "ExportPDF" within 30 days of original purchase sine you can use "Acrobat XI Pro" FREE 30 trial version anyways
    Good  luck everyone. I still say we all complain about not being notified about the waiting period to use our PAID software though

  • I am getting only one record from table data

    Hi Experts,
    I am using interacive forms to bring the table data i used  GET_STATIC_ATTRIBUTES_TABLE
    method. initially the table is empty when i fill some records more than one it is giving me only one record.
    where as i fill the table in wddoinit more than one record and try to retreived it, showing all the records more than one. waht is the reason.. if i fill manually why it is not bringing all the reocrds.
    i have used the cardinatly as follows
    1. parent node(no tables/structure used)
    Dictionary structure       empty not used
    Cardinality 1..1
    Selection 0..1
    Initialization Lead Selection  Checked
    Singleton    Not checked
    Supply Function  not used
    2. table node(i used table type)
    Dictionary structure    SFLIGHT_LIGHT
    Cardinality 1..n
    Selection 0..n
    Initialization Lead Selection  Checked
    Singleton    Not checked
    Supply Function  not used
    Pleae help me out...
    Thanks,
    Mahesh.Gattu

    hi,
    Use the following code for making the rows editable for a table UI element.
      DATA lo_nd_cn_try TYPE REF TO if_wd_context_node.
      DATA lo_el_cn_try TYPE REF TO if_wd_context_element.
      DATA ls_cn_try TYPE wd_this->element_cn_try.
      DATA ls_cn_try1 TYPE wd_this->elements_cn_try.
    navigate from <CONTEXT> to <CN_TRY> via lead selection
      lo_nd_cn_try = wd_context->get_child_node( name = wd_this->wdctx_cn_try ).
    do 5 times.                       
    clear ls_cn_try.
    append ls_cn_try to ls_cn_try1.
    lo_nd_cn_try->bind_table( ls_cn_try1 ).
    enddo.
    ->  cn_try is the node which is binded with the Table UI element.
    What all this is called as initialization of table. This code will make 5 rows editable, If u want more rows editable then run the loop according to the requirement.
    U can write this code in the WDDOINIT.
    Thanks,
    Pankaj Aggarwal.

  • I need a gaming keyboard for my mac but the only ones I can find are for Windows,  there is no Command button or FN button.  Any suggestions?

    So, I have an OS X 10.7.5 and I want to get a gaming keyboard, but the only good ones I can find are for windows.  I know because they have the Windows home key button, and no FN button or Command button.  Any suggestions?

    Normally, most Windows-compatible keyboards are also compatible with Mac OS X. If I'm not mistaken, the Windows key (the key with the Windows icon) is the command key. Also, if you do need to use the F1-F12 keys as standard function keys (you would normally hold FN and then press the button), you can set them to standard function keys in System Preferences. There may be some good gaming keyboards on the market that use the Mac layout, but most may use a Windows keyboard. Personally, I prefer the Mac keyboard on my Macbook. I hope this helps!

  • Sender file adapter Need to Get Only one record Using FCC

    Hi All,
                  I am using File to ABAP Proxy interface, where i need to Trigger my proxy so in my sender file adapter , i need to configure as such it is should take only one record, from whole file i am using Key field parametrs in FCC but it is taking all the records which is not having the key fields also
    please help me
    Thanking you
    Sridhar

    2A64310       1 6V83970       03751650016001154000                    1 6V9961XT-3   13236157001160
    2A64310       1 6V83970                        000                    1 6V9962XT-3   23236162
    2A64730       1 6V83970       03751650016000106000                    1 6V9962XT-3   13236162000112
    2A64730       1 6V83970                        000                    1 6V9961XT-3   23236157
    2A64741 6V99481 6V83971 4S541403751650016000152360                    1 6V9964XT-3   13236168000166
    2A64741 6V99471 6V83971 4S5414                 000                    1 6V9963XT-3   23236167
    2A64772 6V99492 6V83982 3S860605001650017000244000                    2 6V9965XT-3   13289090000248
    2A65690       1 6V97460       07501226872000110000                    11242153L&MP   1
    2A65690       1 6V97460                        000                    11242121L&MP   2
    EOF
    this is sample file , i need to have any one line , cause i need to just trigger a proxy , i am not to going tp take entire file cause in real time i will getting 100 MB file which will be a performance issue

  • How to give only one function module execution Auth for a User ?

    Dear Experts
    I have reviewed S_DEVELOP auth object. It is not ful filling my requirement
    Any Ideas !!
    Rgds

    Rakesh...Firstly thanks for reply.
    As i said i reviewed these and found it is not meeting my requirement.
    As we aware We can control auth to Function modules thru object type
    Filed OBJTYPE----
    FUGR --> 1st control
    and with Function Group Name
    Field OBJNAME----
    <Function Group Name>  --> 2nd control
    In my scenario - I have given the authroizations as below
    ++++++++++++++++++++++++++++++++++++++++++++++++++++
    ACTVT            Activity                                                 Display, Execute
    DEVCLAS       Package                                               *
    OBJNAME      Object name                                         ZECC_FG
    OBJTYPE       Object type                                           FUGR
    P_GROUP       Authorization group ABAP/4 pro              *
    ++++++++++++++++++++++++++++++++++++++++++++++++++++
    The above authroization is giving all Function modules authrozation under ZECC_FG Function Group.
    My Requirement
    I shoudl be able to give only one Function Module of a Function group where multiple function modules exist under the same Function Group.
    How can i acheiveit. Any Custom Control can be place to acheive this.
    I am sure S_DEVELOP will not solve my requirement (I Beleive)
    Regards

  • Creating only one or several invoice smartforms for a global company

    Hi,
    I'd like to hear your thoughts how smartform development should be arranged for a global company. Let's take an invoice as an example.
    A global company has several divisions, company codes, plants and sales organizations. Invoices are printed in different languages in several countries.
    Of course it would be better to build exactly one smartform for everything, but on the other hand, the smartform would be extreme complex and difficult to maintain in future, since each company has slightly different requirements for the invoice. On the other hand, it doesn't make any sense to just keep on creating a new smartform for each country, since at the end you will have tens of almost identical smartforms which doesn't sound good either.
    What is your experience--should one try to build exactly one smartform for all the company codes, or would it be better to create a new smartform for each company code? In general, I would say that the latter one is perhaps a better approach.
    Thanks in advance for your thoughts,
    Jarmo Tuominen
    Edited by: Jarmo Tuominen on Mar 1, 2008 12:17 PM

    My first thought was that it is better to maintain only one form for everything.
    However, I am aware that there are also opposite opinions. They explain that creating one form for everything is not the best approach. Because of this, I would like to understand the reasons for that. Do others have any other point of views?

  • SAP Query - Selection to get only one record by date

    I am writing a query in which the infoset includes dates example would be material, plant, date, price.  For a given material and plant, there will be multiple records in the infoset because the material can have a different price on a different date.
    I want to choose the one record from the infoset that has a date closest to but less than or equal to a user entered date.
    How do I do this.
    Steven Engel

    Not answered, but I no longer need

  • How to get only the first level of nodes for a subform?

    How can we get only the first level of nodes of a subform?
    For ex:
    Form1
         SubForm1
              Text1
              Text2
              RadioButton1
         SubForm2
              Text1
              Text2
              RadioButton1
         SubForm3
              Text1
              Text2
                   SubForm31
                        RadioButton1
    In this heirarchy if we give Form1.nodes will refer to all nodes under the Form1 (SubForm1,Test1,Text2,RadioButton1,SubForm2,...SubForm31, RadioButton1 etc..)
    But is there any way that we can access only the first level of nodes of Form1 ie can we get only (SubForm1,SubForm2,SubForm3) for Form1 in any Way..?
    Thanks.

    Two ways .....
    1. Use Javascript E4X instead ...there are nice functions for getting children of parents.
    2. Cycle through all of the form1.nodes and look for objects that have a className of "subform". For loops are useful for this task.
    Make sense?
    Paul

  • Only one PR should be created for 3 months requirement.

    Dear All,
    In MRP run only 1 PR should be created for three months rquirement ,
    Eg: The procurement is done only once in 3 months, means PO is raised only once in 3 months for a material. So now system should create only 1 PR [1 lot] for 3 months requirement.
    I have tried to creating a new  lot size in OMI4 and i assigned "No of periods" as '3', and assigned in material master, but still system creates PR many PR's. What could be wrong,
    Thanks in Advance
    Praveen...........

    Any inputs ??

Maybe you are looking for