Need query for..

Table A               
ID     Name     Date     Paid
1     A     5-Sep-11     10
1     A     6-Sep-11     12
1     A     7-Sep-11     15
2     B     6-Sep-11     13
2     B     7-Sep-11     16
2     B     8-Sep-11     5
3     C     8-Sep-11     12
3     C     9-Sep-11     11
Output Req               
When passed ID and Name as filter conditions then output Latest Paid
e.g
for 1,A--->15
for 2,B--->5
for 3,C--->11
I blv this can be done using rank but I m looking for a way to do it without using a subquery.
Thanks in advance.

Try this
"afiedt.buf" 17 lines, 699 characters
  1  with t
  2  as
  3  (
  4  select 1 id, 'A' name, to_date('05-Sep-11','dd-mon-rr') dt, 10 paid from dual union all
  5  select 1, 'A', to_date('06-Sep-11','dd-mon-rr'), 12 from dual union all
  6  select 1, 'A', to_date('07-Sep-11','dd-mon-rr'), 15 from dual union all
  7  select 2, 'B', to_date('06-Sep-11','dd-mon-rr'), 13 from dual union all
  8  select 2, 'B', to_date('07-Sep-11','dd-mon-rr'), 16 from dual union all
  9  select 2, 'B', to_date('08-Sep-11','dd-mon-rr'), 05  from dual union all
10  select 3, 'C', to_date('08-Sep-11','dd-mon-rr'), 12 from dual union all
11  select 3, 'C', to_date('09-Sep-11','dd-mon-rr'), 11 from dual
12  )
13  select id, name, max(paid) keep(dense_rank last order by dt) paid
14    from t
15   group
16*     by id, name
SQL> /
        ID N       PAID
         1 A         15
         2 B          5
         3 C         11

Similar Messages

  • Need Query for empty partitions

    I am having nearly 700 partitions for a table.Now i want to find out only the empty partitions.I need query for that.
    Thankx..

    Not the most elegant solution, but it works:
    declare
    rc number;
    str varchar2(200);
    begin
    for i in (select table_owner, table_name, partition_name from dba_tab_partitions) loop
    str := 'select count(*) from ' || i.table_owner || '.' || i.table_name || ' partition (' || i.partition_name || ')';
    execute immediate str into rc;
    if rc = 0 then
    dbms_output.put_line(i.table_owner || '.' || i.table_name);
    end if;
    end loop;
    end;

  • Need Query for Item Relationship of Oracle Apps

    Hello Team,
    I need the Query to select the Item Relationship.
    In Oracle Apps we have different tyes of Structure
    ItemA -> ItemB
    ItemB -> ItemC
    ItemC -> ItemD
    ItemG -> ItemH
    ItemK -> ItemL
    ItemW -> ItemQ
    and this also is possible (meand many to one relationship)
    ItemA -> ItemB
    ItemB -> ItemC
    ItemC -> ItemD
    ItemT -> ItemD
    and in the Select Query i want the below result
    ItemA -> ItemB 1
    ItemB -> ItemC 2
    ItemC -> ItemD 3
    ItemG -> ItemH 1
    ItemK -> ItemL 2
    ItemW -> ItemQ 1
    and this also is possible (means many to one relationship)
    ItemA -> ItemB 1
    ItemB -> ItemC 2
    ItemC -> ItemD 3
    ItemT -> ItemD 1
    means i want the Hierarchy number also
    Please help me to in order to get the relationship by sql query.
    Kind Regards,

    thanks for the quick response and i would love to spend time perusing the forum for this question but i didn't have time today.  i'll do that now though.
    what i'm mostly interested in is a chronological view (lastUpdateDate) of the change to pricing for an item in the system.  there is a lot of activity in our system around price changes for promotions and i want to keep track of when it's changed in the source system and pair that with our other downstream systems.
    i'm assuming we can add this functionality through a udf some way or maybe sp_TransNotification proc?

  • Need query for requistion and rfq numbers

    Dear All,
    I need a query to list all requisition number for which RFQ is created and RFQ  is partially converted to PO, if RFQ is fully converted to PO, it should not fetch the details.please help me on this.
    Thanks
    Debendra

    Are you referring to sourcing RFQ or core quotations?

  • Need Query for this

    Report Builder Version:10g
    Hi Guys Good Morning to one and all
    I have a table Named Onlsuvdet which captures the answers from
    an online survey front end which has multiple choice questions.
    the table structure is as follows
    create table onlsuvdet(shloid number,questno char(5),respo1 char(5),respo2 char(5));
    and the sample data is as follows
    SHLOID QUEST RESPO RESPO
    9315 1 2
    9315 2 3
    9315 3 4
    9315 3 5
    9315 4 1
    9315 5 2
    9315 5 1
    Now i want the result as follows
    shlogid quest1 quest2 q3 q4 q5
    9315     2 3 4,5 1 2,1
    So my requirement is a query which displays this data as above.
    Please helpppp
    Any help will be appreciated :)
    Thanks & Regards

    Hi,
    user123 wrote:
    Report Builder Version:10g
    Hi Guys Good Morning to one and all
    I have a table Named Onlsuvdet which captures the answers from
    an online survey front end which has multiple choice questions.
    the table structure is as follows
    create table onlsuvdet(shloid number,questno char(5),respo1 char(5),respo2 char(5));Thanks for posting the CREATE TABLE statement. That helps.
    Why are you using the CHAR datatype, rather than VARCHAR2? CHAR is nothing but trouble.
    and the sample data is as follows
    SHLOID QUEST RESPO RESPO
    9315 1 2
    9315 2 3
    9315 3 4
    9315 3 5
    9315 4 1
    9315 5 2
    9315 5 1Always post your data in a form people can use to re-create the problem and test their solutions. for example:
    INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '1    ', '2    ', NULL);
    INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '2    ', '3    ', NULL);
    INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '3    ', '4    ', NULL);
    INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '3    ', NULL, '5    ');
    INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '4    ', '1    ', NULL);
    INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '5    ', '2    ', NULL);
    INSERT INTO onlsuvdet (shloid, questno, respo1, respo2) VALUES (9315, '5    ', NULL, '1    ');I'm making a lot of guesses about the data. for example, I'm guessing there will never be more than 2 rows with the same shloid and questno.
    Why do you have 2 columns, respo1 and respo2? Is exactlyly one of them always NULL? If respo1 is NULL, will there always be another row with the same shloid and questno, but with a NULL respo2?
    Now i want the result as follows
    shlogid quest1 quest2 q3 q4 q5
    9315     2 3 4,5 1 2,1Be consistent with the column names; either call them all questn (like I did below) or call them all qn.
    So my requirement is a query which displays this data as above.Perhaps something like this:
    WITH     joined_data     AS
         SELECT     r1.shloid
         ,     r1.questno
         ,     RTRIM ( r1.respo1 || ',' || r2.respo2
                    )     AS respo
         FROM                onlsuvdet     r1
         LEFT OUTER JOIN     onlsuvdet     r2  ON     r1.shloid     = r2.shloid
                                         AND     r1.questno     = r2.questno
                                         AND     r1.respo1     IS NOT NULL
                                 AND     r2.respo2     IS NOT NULL
    SELECT       shloid
    ,       MAX (CASE WHEN questno = '1    ' THEN respo END)     AS quest1
    ,       MAX (CASE WHEN questno = '2    ' THEN respo END)     AS quest2
    ,       MAX (CASE WHEN questno = '3    ' THEN respo END)     AS quest3
    ,       MAX (CASE WHEN questno = '4    ' THEN respo END)     AS quest4
    ,       MAX (CASE WHEN questno = '5    ' THEN respo END)     AS quest5
    FROM       joined_data
    GROUP BY  shloid
    I hope this answers your question.
    If not, point out a few places where the query above gets the wrong results. Post the correct results (formatted, between \ tags, as explained in the FAQ
    http://wiki.oracle.com/page/Oracle+Discussion+Forums+FAQ
    ) and explain how you get the correct results from the given data.  Correct or add to the sample data that I psoted, if necessary.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Need Query for Update

    CREATE TABLE TEST_MATCH
    MTCH1 NUMBER(9),
    MTCH2 NUMBER(9),
    UPDT_MTCH CHAR(2 BYTE),
    UPDT_NBR NUMBER(10)
    SET DEFINE OFF;
    Insert into TEST_MATCH
    (MTCH1, MTCH2, UPDT_MTCH)
    Values
    (2616131, 300137070, '02');
    Insert into TEST_MATCH
    (MTCH1, MTCH2, UPDT_MTCH)
    Values
    (2571056, 300129277, '02');
    Insert into TEST_MATCH
    (MTCH1, MTCH2)
    Values
    (2623529, 300175046);
    COMMIT;
    i need to update the column UPDT_NBR which is currently NULL
    UPDATE TEST_MATCH
    SET UPDT_NBR =
    NVL(2616131, 300137070) FOR THESE TWO MATCHES-> (1234567),
    (2571056, 300129277) FOR THESE TWO MATCHES -> (1111111),
    (2623529, 300175046) FOR THESE TWO MATCHES ->(222222);
    Thanks for all your help in my previous post. And thanks again for looking into my post.

    Hi,
    If it is just three records it would be better if you fire individual update statement 3 times.
    But if it is a sample data only and you have many updates to do then only way I think it is is possible is either by creating temporary table or using subfactoring(same as creating temporary table)
    Regards
    Anurag

  • Need query for refresh test database.

    Hi,
    I want refresh production database to test database refresh using expdp dumpfile. Please provide steps this is the requirement
    This request is to refresh the Tecnomatix test database MFEM which is
    on the NATEST server wnmcdwtk.natest.gm.com. This database needs to
    be refreshed using an Oracle full backup dump file from the Tecnomatix
    production database MFEP which runs on the production NAENG server
    wnmcdds8.naeng.gm.com. The MFEM and MFEP databases are both at Oracle
    v10.2.0.4.

    Hi,
    You have posted to the wrong section of the forum. This forum us for Berkeley DB.
    Regards,
    Alex Gorrod
    Oracle Berkeley DB

  • Need query for Item - Price Change History

    I need help finding information around Price Change History by Price List. 
    Information of interest is Date of Update and By Whom.    Also, if a Datasource is 'N-Unknown', what does this generally mean?
    select
    i.itemcode,
    i.itemname,
    iphist.price,
    pl.listname,
    pl.datasource as 'ChangeSource',
    '' as 'PriceChangeUpdateDate',
    '' as 'UpdateByUser'
    from  ait1 iphist, oitm i, opln pl
    where 1=1
    and iphist.pricelist = pl.listnum
    and i.itemcode = iphist.itemcode
    and iphist.itemcode in ('1234')
    and pl.listnum in (6)
    thanks in advance...

    thanks for the quick response and i would love to spend time perusing the forum for this question but i didn't have time today.  i'll do that now though.
    what i'm mostly interested in is a chronological view (lastUpdateDate) of the change to pricing for an item in the system.  there is a lot of activity in our system around price changes for promotions and i want to keep track of when it's changed in the source system and pair that with our other downstream systems.
    i'm assuming we can add this functionality through a udf some way or maybe sp_TransNotification proc?

  • Need query for this logic..

    Hi,
    Need a SQL query to achieve this..
    Ex:
    Select object_name from user_objects where object_name in('EMP','DEPT')
    You will get 2 table names.
    DEPT
    EMP
    Now I want to count how many records are there in each table
    Output should be like
    DEPT 4
    EMP 13
    Please let me know how can we write it ?
    Thanks in Advance
    Devender

    You need to create a function to cout rows.
    Here is an example
    CREATE OR REPLACE
    FUNCTION get_rows (
         t_owner IN varchar2 default user,
        t_name IN varchar2
    RETURN  integer
    IS
         outVal integer;
    BEGIN
         select null
         into outVal
         from dba_tables
         where ( owner=t_owner )
              and ( table_name=t_name );
        execute immediate 'select count(*) from '||t_owner||'.'||t_name into outVal;
        RETURN outVal;
    EXCEPTION
         WHEN no_data_found THEN
              return null;
    END;
    /And here is the query.
    Processing ...
    select owner,object_name,get_rows(owner,object_name) n_rows
    from dba_objects
    where object_name in('EMP','DEPT')
    Query finished, retrieving results...
           OWNER                       OBJECT_NAME                                          ROWS                
    SCOTT                    EMP                                                                       14
    SCOTT                    DEPT                                                                       4
    2 row(s) retrieved

  • Need query for connecting flights

    Hi all.
    My requirement is as follows
    suppose my itnery is AAA-BBB-CCC.And there are few flights between AAA-BBB and BBB-CCC.I need all the valid connecting flights everyday.My table data is as follows
    orig dest fltno arrivaldate depdate legno itid
    AAA BBB 121 23-05-2011 15:40:00(arrical ar BBB) 1 x
    AAA BBB 123 23-05-2011 16:40:00(arrical ar BBB) 1 x
    BBB CCC 212 24-05-2011 04:05:00(arrical ar CCC) 23-05-2011 19:50:00(depat from BBB) 2 x
    BBB CCC 213 24-05-2011 13:05:00 (arrical ar CCC) 24-05-2011 04:50:00(depat from BBB) 2 x
    now i need to get for legno 1 all the flights in leg 2, whose depdate is grater than arrival date in leg 1.
    Thanks.

    Hi,
    Whenever you have a problem, please post CREATE TABLE and INSERT statements for the sample data. Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Always say which version of Oracle you're using.
    If I understand the problem, then you can use somehting like this:
    SELECT     l2.*
    FROM     table_x       l1
    JOIN     table_x       l2   ON   l2.legeno     = l1.legno + 1
                     AND  l2.orig     = l1.dest
                     AND  l2.depdate     > l1.arrivaldate
    WHERE     l1.legno     = 1
    ;A self-join, like this, will work if you're looking for a specific leg. If you're interested in all legs (or all legs after a certain point), regardless of whether that's 1, 2, 3 or more, then use CONNECT BY instead of a self-join.

  • Need query for below requirement

    create table nsk_temp2 (num number,parent_num number,src_num number);
    insert into nsk_temp2 values (1000,null,null);
    insert into nsk_temp2 values (1001,1000,null);
    insert into nsk_temp2 values (1002,1000,null);
    insert into nsk_temp2 values (1010,null,1000);
    insert into nsk_temp2 values (2001,1010,null);
    insert into nsk_temp2 values (2002,1010,null);
    num  parent_num  src_num
    1000          
    1001     1000     
    1002     1000     
    1010          1000
    2001     1010     
    2002     1010     
    Expected output
    num  parent_num  src_num
    1000          
    1001     1000     
    1002     1000     
    1010          1000
    2001     1010     1001
    2002     1010     1002
    2001 -> parent is 1010 and 1010 src_num is 1000 and 1000 is parent for 1001 and 1002, so 1001 and 2001 are identical records

    Hi,
    This does what you requested:
    WITH     got_r_num     AS
         SELECT     num, parent_num, src_num
         ,     ROW_NUMBER () OVER ( PARTITION BY  parent_num
                                   ORDER BY          num
                           )         AS r_num
         FROM    nsk_temp2
    SELECT       d.num, d.parent_num
    ,       NVL ( d.src_num
               , s.num
               )          AS src_num
    FROM           got_r_num  d
    LEFT OUTER JOIN      got_r_num  m  ON  m.num     = d.parent_num
    LEFT OUTER JOIN      got_r_num  s  ON  s.parent_num     = m.src_num
                                   AND s.r_num     = d.r_num
    ORDER BY  d.num
    ;Whether or not it gets the right results for the right reasons, I can't say, since I know so little about the reasons.
    If 1001 and 2001 are identical, aren 1001 and 2002 identical, too? Can the parent_num/num hierarchy extend beyond 2 levels? What would happen if 1000 had more, or fewer, children than 2000?

  • Need query for email id replace

    Hi All,
    i have the input as a email like --'[email protected]'
    need output only the --'arun' .
    please give me the solution...

    try this..,
    SQL> with tab as
      2  (
      3  select '[email protected]' email from dual)
      4  select substr(email,1,instr(email,'@')-1) from tab;
    SUBS
    arunYou can use
    update <tablename>
    set email=substr(email,1,instr(email,'@')-1)
    where=<condition>Twinkle
    Edited by: Twinkle on Oct 21, 2009 11:03 AM

  • Need query for software Last Used details

    Hi All,
    Is there any SCCM report which gives us details of software last used date, username, hostname etc. so that we can manage our licensing.
    Regards,
    Prem

    Yes: Software Metering in Configuration Manager
    http://technet.microsoft.com/en-us/library/bb694169.aspx
    Don
    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable.
    This helps the community, keeps the forums tidy, and recognises useful contributions. Thanks!)

  • QUERY FOR CUSTOMERS FULL DEBIT AND CREDIT WITH CLOSING BALANCE

    Hi Friends,
       I need query for CUSTOMERS FULL DEBIT AND CREDIT WITH CLOSING BALANCE for selection criteria from date and to date.
       I know the Trial Balance Report will sort out this issue... but i need routeday wise report
    1. Business Partner Master Data - i created one UDF field called U_Routeday (MONDAY, TUESDAY, WEDNESDAY,THURSDAY,FRIDAY)
    2. The query should be like selection criteria 
                                  - Routeday [%0]
                                  - Posting Date [%1]                           
                                  - Posting Date [%2]
    CardCode
    Debit
    Credit
    Balance
    D10503
    25031.50
    24711.50
    2962.00
    D10641
    5466.00
    7460.00
    285.00
    D10642
    2866.00
    142.00
    give any helpful query ASAP... Thanks in advance

    Hi,
    Try this query:
    Declare
    @fromdate as datetime
    Declare
    @Todate as datetime
    Declare
    @Code as nvarchar(25)
    set
    @fromdate = ( select min(Ta.[RefDate]) from OJDT ta where
    Ta.[RefDate] >= [%0])
    set
    @Todate = ( select max(Tb.[RefDate]) from OJDT tb where Tb.[RefDate]
    <= [%1])
    set
    @code = (select max(Tc.[ShortName]) from JDT1 tC where Tc.[ShortName]
    = [%2])
    SELECT
    [Name] as AcctName, [Jan]= sum([1]), [Feb]= sum([2]), [Mar]=
    sum([3]), [Apr]= sum([4]),  [May]= sum([5]), [June]= sum([6]),
    [July]= sum([7]), [Aug]= sum([8]), [Sept]= sum([9]), [Oct]=
    sum([10]), [Nov]= sum([11]), [Dec]= sum([12]), total = sum
    (isnull([1],0)+ isnull([2],0) + isnull([3],0) + isnull([4],0) +
    isnull([5],0) + isnull([6],0) + isnull([7],0) + isnull([8],0) +
    isnull([9],0)+ isnull([10],0) + isnull([11],0) + isnull([12],0))
    from
    (SELECT
    T0.[ShortName] as Name, sum(T0.[Debit]-T0.[Credit]) as T,
    month(T2.[RefDate]) as month FROM JDT1 T0  INNER JOIN OACT T1 ON
    T0.Account = T1.AcctCode INNER JOIN OJDT T2 ON T0.TransId =
    T2.TransId WHERE T2.[RefDate] between @fromdate and @todate and
    T0.[ShortName]  = @code  GROUP BY T0.[ShortName],T2.[RefDate] ) S
    Pivot
    (sum(T)
    For  Month IN ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12])) P
    group
    by [Name],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]
    Let me know your result.
    Thanks & Regards,
    Nagarajan

  • Need query to find out whether exactly 2 columns are used in any index ?

    Suppose i have two columns ID and Status (or any number of columns ) belongs to table customer...
    Now I want to create below index
    Ex. create index test1 on customer (ID , Status )
    But before creating this index i want to check that whether there is already index on these 2 columns ? May be by other name ?
    Need query for this.
    Plz help.

    Hi Shubhangi,
    Your requirement is very difficult to fulfill , i have made an attempt to replicate your reqrmnt & write a query wherein you need to compromise on few things , let us see if it works for you
    Supply table_name/owner & Number of column on which you want to find indexes
    e.g.
    select distinct INDEX_NAME,column_name
    from dba_ind_columns
    where index_name in (select distinct index_name
    from dba_ind_columns
    where table_name='&table_name'
    and table_owner='&owner'
    having count(column_name)=&column_count group by index_name);
    Enter value for table_name: ADDRESS
    Enter value for owner: ASAP
    Enter value for column_count: 2
    INDEX_NAME COLUMN_NAME
    FKIDX_AD__SF_ST_FO SF_STRUC_FORMAT_NM
    FKIDX_AD__SF_ST_FO SF_TYPE_NM
    SQL> /
    Enter value for table_name: ADDRESS
    Enter value for owner: ASAP
    Enter value for column_count: 3
    INDEX_NAME COLUMN_NAME
    FKIDX_AD__SF_ST_FO_1 POSTAL_CD
    FKIDX_AD__SF_ST_FO_1 SF_STRUC_FORMAT_NM
    FKIDX_AD__SF_ST_FO_1 SF_TYPE_NM
    Thanks,
    Ajay More
    http://moreajays.blogspot.com

Maybe you are looking for

  • ICal synch between MacBook and iPhone using iCloud

    when I create an event in iCal it synchs to my iPhone via iCloud but, when I create an event in iCal using integration with Mail, the event does not show up on iPhone.

  • How to include files in isolated storage

    I am developing an app that has some static files that I need to access. I would like to be able to include those files in my VS project and have them loaded to Isolated Storage when the app is installed on the phone. I am accessing the file with Iso

  • I can't get the latest ota on my Note 4

    I missed the lollipop update after the NK3 update on my Note 4 and I can't receive any updates even after manually searching for available ones in settings>General >About. Is there anything I can do that doesn't involve updating by Odin or kies?

  • Stock returns/RMA Stock

    I am using SAP B1 to manage receipts and issues of stock with suppliers and customers and manage stock on a FIFO basis.  Most stock is serial number tracked and I want to see full history on the serial number My issue relates to damaged stock where I

  • Top & bottom print ie: date, web page, in margins are illegible. Content of page is fine.

    Have tried changing fonts before printing as well as margins but what prints across the top and bottom is illegible. The page contents is fine. The illegible part is what prints in the top & bottom margins: web page, date, page # etc, This does not h