Urgent help in multiple table update query

TABLE1
NAME
RATE
TABLE2
NAME RATE1 DATE1
NAME RATE2 DATE2
NAME RATE3 DATE3
Can anyone help me to write a query which can update RATE in TABLE1 based on
following criteria ?
We have same column 'NAME' in both the tables.
First Find maximum Date from the TABLE2 and then take correspoinding rate from TABLE2 and update with the RATE column in TABLE1.

Works as expected for me:
SQL> CREATE TABLE TABLE1 (
  2   NAME VARCHAR2(10),
  3   RATE NUMBER
  4  );
Tabelle wurde erstellt.
SQL> CREATE TABLE TABLE2 (
  2   NAME VARCHAR2(10),
  3   RATE NUMBER,
  4   DT DATE
  5  );
Tabelle wurde erstellt.
SQL> INSERT INTO TABLE1 VALUES ('NAME1', NULL);
1 Zeile wurde erstellt.
SQL> INSERT INTO TABLE1 VALUES ('NAME2', NULL);
1 Zeile wurde erstellt.
SQL> INSERT INTO TABLE1 VALUES ('NAME3', NULL);
1 Zeile wurde erstellt.
SQL>
SQL> INSERT INTO TABLE2 VALUES ('NAME1', 1, SYSDATE);
1 Zeile wurde erstellt.
SQL> INSERT INTO TABLE2 VALUES ('NAME1', 2, SYSDATE-1);
1 Zeile wurde erstellt.
SQL> INSERT INTO TABLE2 VALUES ('NAME1', 3, SYSDATE-2);
1 Zeile wurde erstellt.
SQL>
SQL> INSERT INTO TABLE2 VALUES ('NAME2', 1, SYSDATE+1/1440);
1 Zeile wurde erstellt.
SQL> INSERT INTO TABLE2 VALUES ('NAME2', 2, SYSDATE+2/1440);
1 Zeile wurde erstellt.
SQL> INSERT INTO TABLE2 VALUES ('NAME2', 3, SYSDATE+3/1440);
1 Zeile wurde erstellt.
SQL> update table1 t1 set
  2    rate = (select t2.rate
  3              from table2 t2
  4             where t2.dt  = (select max(t3.dt)
  5                                from table2 t3
  6                               where t3.name=t2.name
  7                             )
  8               and t2.name=t1.name
  9           );
3 Zeilen wurden aktualisiert.
SQL> select name, rate from table1;
NAME             RATE                                                          
NAME1               1                                                          
NAME2               3                                                          
NAME3                                                                          
SQL> INSERT INTO TABLE2 VALUES ('NAME3', 1, TRUNC(SYSDATE));
1 Zeile wurde erstellt.
SQL> INSERT INTO TABLE2 VALUES ('NAME3', 2, TRUNC(SYSDATE));
1 Zeile wurde erstellt.
SQL> update table1 t1 set
  2    rate = (select t2.rate
  3              from table2 t2
  4             where t2.dt  = (select max(t3.dt)
  5                                from table2 t3
  6                               where t3.name=t2.name
  7                             )
  8               and t2.name=t1.name
  9           )
10  ;
  rate = (select t2.rate
FEHLER in Zeile 2:
ORA-01427: Unterabfrage für eine Zeile liefert mehr als eine Zeile

Similar Messages

  • Urgent Help required in Tunning this query

    I have table ACCOUNT SPONSOR HOMESTORE ASH with more than 30 million rows.
    My batch daily need to update or insert into this table from a temporary table TEMP_HSTRALCT. The data for temporary table is populated by below query which selects from two tables TRANSACTION POINTS and REDEMPTIONS.However both these tables are partitioned on date time and is run daily and this is running for hours.
    Can anyone please help me on tuning this query
    INSERT INTO temp_hstralct
    (tmp_n_collector_account_num, tmp_v_location_id,
    tmp_v_sponsor_id, tmp_v_source_file_name,
    tmp_n_psc_insert_ind, tmp_n_psc_update_ind,
    tmp_n_transaction_amount, tmp_n_transaction_points,
    tmp_n_acc_insert_ind, tmp_n_ash_insert_ind,
    tmp_n_col_insert_ind, tmp_n_check_digit,
    tmp_n_collector_issue_num, tmp_n_csl_insert_ind,
    tmp_v_offer_code, tmp_n_psa_insert_ind)
    SELECT DISTINCT trp_n_collector_account_num account_num,
    trp_v_location_id location_id,
    trp_v_sponsor_id sponsor_id,
    trp_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
    FROM transaction_points, ACCOUNT, locations_master,homestores
    WHERE hsr_v_accrual_allowed = 'Y'
    AND trp_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
    AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
    OR ACCOUNT.acc_v_account_type IS NULL
    AND hsr_v_b2c_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'B'
    AND hsr_v_nfb_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'H'
    AND hsr_v_hybrid_accounts = 'Y'
    AND trp_d_creation_date_time BETWEEN SYSDATE-3
    AND SYSDATE
    AND trp_v_sponsor_id = 'JSAINSBURY'
    AND trp_v_location_id =
    locations_master.lnm_v_location_id
    AND locations_master.lnm_v_partner_id = 'JSAINSBURY'
    AND ( ( ( (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND (INSTR
    (hsr_v_store_type,
    locations_master.lnm_c_location_type
    ) > 0
    AND hsr_v_homestore_assignment = 'ST'
    OR ( ( locations_master.lnm_c_homestore_ind =
    'Y'
    AND (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND hsr_v_homestore_assignment = 'HS'
    UNION ALL
    SELECT DISTINCT rdm_n_collector_account_num account_num,
    rdm_v_location_id location_id,
    rom_v_supplier_id sponsor_id,
    rdm_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
    FROM redemption_details,
    reward_offer_master,
    ACCOUNT,
    locations_master,
    HOMESTORES
    WHERE hsr_v_redemption_allowed = 'Y'
    AND rdm_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
    AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
    OR ACCOUNT.acc_v_account_type IS NULL
    AND hsr_v_b2c_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'B'
    AND hsr_v_nfb_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'H'
    AND hsr_v_hybrid_accounts = 'Y'
    AND rdm_d_creation_date_time BETWEEN SYSDATE-3
    AND SYSDATE
    AND rom_v_reward_offer_id = rdm_v_reward_id
    AND rom_v_supplier_id = 'JSAINSBURY'
    AND rdm_v_location_id =
    locations_master.lnm_v_location_id
    AND locations_master.lnm_v_partner_id ='JSAINSBURY'
    AND ( ( ( (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND (INSTR
    (hsr_v_store_type,
    locations_master.lnm_c_location_type
    ) > 0
    AND hsr_v_homestore_assignment = 'ST'
    OR ( ( locations_master.lnm_c_homestore_ind =
    'Y'
    AND (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND hsr_v_homestore_assignment = 'HS'
    );

    I have copied the explain as it is and can you please try pasting in the text pad.Can you let me know whether parallel hint on this will speed up the select queries.
              Plan
              INSERT STATEMENT CHOOSECost: 410,815 Bytes: 2,798,394 Cardinality: 15,395                                                        
                   32 UNION-ALL                                                   
                        15 SORT UNIQUE Cost: 177,626 Bytes: 2,105,592 Cardinality: 11,896                                              
                             14 FILTER                                         
                                  13 HASH JOIN Cost: 177,312 Bytes: 2,105,592 Cardinality: 11,896                                    
                                       2 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 23,184 Cardinality: 966                               
                                            1 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 1                          
                                       12 FILTER                               
                                            11 HASH JOIN OUTER                          
                                                 8 MERGE JOIN CARTESIAN Cost: 155,948 Bytes: 702,656,660 Cardinality: 4,845,908                     
                                                      3 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1                
                                                      7 BUFFER SORT Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908                
                                                           6 PARTITION RANGE ITERATOR Partition #: 12           
                                                                5 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.TRANSACTION_POINTS Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908 Partition #: 12      
                                                                     4 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_TRANSACTION_POINTS_1 Cost: 24,880 Cardinality: 6,978,108 Partition #: 12
                                                 10 PARTITION RANGE ALL Partition #: 15 Partitions accessed #1 - #5                    
                                                      9 TABLE ACCESS FULL LMHOLTP.ACCOUNT Cost: 6,928 Bytes: 68,495,680 Cardinality: 8,561,960 Partition #: 15 Partitions accessed #1 - #5               
                        31 SORT UNIQUE Cost: 233,189 Bytes: 692,802 Cardinality: 3,499                                              
                             30 FILTER                                         
                                  29 FILTER                                    
                                       28 NESTED LOOPS OUTER                               
                                            24 HASH JOIN Cost: 226,088 Bytes: 664,810 Cardinality: 3,499                          
                                                 16 TABLE ACCESS FULL LMHOLTP.REWARD_OFFER_MASTER Cost: 8 Bytes: 2,280 Cardinality: 114                     
                                                 23 HASH JOIN Cost: 226,079 Bytes: 8,327,280 Cardinality: 48,984                     
                                                      20 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 432 Cardinality: 18                
                                                           19 NESTED LOOPS Cost: 39 Bytes: 2,304 Cardinality: 18           
                                                                17 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1      
                                                                18 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 966      
                                                      22 PARTITION RANGE ITERATOR Partition #: 28                
                                                           21 TABLE ACCESS FULL LMHOLTP.REDEMPTION_DETAILS Cost: 226,019 Bytes: 261,636,270 Cardinality: 6,229,435 Partition #: 28           
                                            27 PARTITION RANGE ITERATOR Partition #: 30                          
                                                 26 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.ACCOUNT Cost: 2 Bytes: 8 Cardinality: 1 Partition #: 30                     
                                                      25 INDEX UNIQUE SCAN UNIQUE LMHOLTP.CO_PK_ACCOUNT Cost: 1 Cardinality: 1 Partition #: 30

  • Help needed with an update query

    Hi,
    I am trying to execute an update query on a table. Here is an example: I have 2 tables t1 and t2 and these tables have 2 similar columns, c11 and c12 in t1 and c21 and c22 in t2. I have to now execute an update statement for the column c11 in t1 with the values for c21 in t2 where the c12 in t1 is equal to c22 in t2. So, the query which I have formulated is:
    update t1 set c11 =
    (select t2.c21 from t1,t2 where t1.c11=t2.c22)
    where t1.c11 in (select t1.c11 from t1);
    But this query gives me an error: ORA-01427: single-row subquery returns more than one row.
    Where am i going wrong? Kindly help.

    Hi,
    CrazyAnie wrote:
    Hi,
    I am trying to execute an update query on a table. Here is an example: I have 2 tables t1 and t2 and these tables have 2 similar columns, c11 and c12 in t1 and c21 and c22 in t2. I have to now execute an update statement for the column c11 in t1 with the values for c21 in t2 where the c12 in t1 is equal to c22 in t2. So, the query which I have formulated is:
    update t1 set c11 =
    (select t2.c21 from t1,t2 where t1.c11=t2.c22)
    where t1.c11 in (select t1.c11 from t1);
    But this query gives me an error: ORA-01427: single-row subquery returns more than one row.
    Where am i going wrong? Kindly help.Whenever you have a problem, post a little sample data (CREATE TABLE and INSERT statements for all tables) and the results you want from that data.
    In this case, where the problem involves changing t1, the INSERT statements should show reflect the state of the tables before the UPDATE, and the results are shat's in t1 after the UPDATE.
    Without that information, people can only guess at the solution.
    As the error message said, the problem is that the sub-query:
    (select t2.c21 from t1,t2 where t1.c11=t2.c22) is returning more than one row. Each row of t1 can only have one value for c11; which one is it supposed to be?
    It's unusual to have an UDPATE on a table be based on a join of that same table and another table. It's not necessarily wrong, but a more common UPDATE statement is:
    update  t1
    set      c11 = (     select      t2.c21
              from      t2
              where     t1.c12     = t2.c22
    where      t1.c12 in ( select  c22
                  from    t1
                );But again, I don't know where you're starting from (sample data), or where you want to go (results from that data), so it's hard to give you good directions.

  • Help with multiple table joins

    I'm trying to limit the results of a query joining multiple tables. I have a main table, tbl_webrequests, and multiple tables with supporting information. The unique column for tbl_webrequests is reqID. There is another table, tbl_instructions, that holds all the instructions tied to each request. I join the tables using reqID.
    I'm trying to construct a page that has all of the records in tbl_webrequests. The problem I'm having is that with each request that has multiple instructions, I have multiple results because of the multiple instructions for one reqID. For now, all I want is the original instruction to display. Below is the original query, and below that is what I'm trying to get the query to do for each record in tbl_webrequest. Note that 319 is a random uniqueID in tbl_webrequests.
    SELECT
    DISTINCT W.reqID, W.dt_close, W.dt_due, W.subject, W.statusid, W.empID, W.priorityid, W.assigneeid, W.categoryid, W.url, W.hrs,
    W.closingNotes, W.mins, W.requestTypeID, I.instructions, I.instID
    from tbl_webrequests W left join
    (select reqID, instID, instructions from tbl_instructions) I on W.reqID = I.reqID
    ORDER BY I.instID asc;
    SELECT
    distinct I.instructions, I.instID, W.reqID, W.dt_close, W.dt_due, W.subject, W.statusid, W.empID, W.priorityid, W.assigneeid, W.categoryid, W.url, W.hrs,
    W.closingNotes, W.mins, W.requestTypeID
    from tbl_webrequests W left join
    (select reqID, instID, instructions from tbl_instructions where rowNum = 1 and reqid = 319 order by instID asc) I on W.reqID = I.reqID
    where W.reqID = 319
    ORDER BY I.instID asc;
    My question is, how do I pass the reqID as a variable into the join subquery so that the query returns only returns the first joined item in tbl_instructions for each record in tbl_webrequests?
    Any help is appreciated
    Thanks!

    Scrap the "DISTINCT" and try something like this:
    Select
           I.Instructions, I.Instid
         , W.Reqid, W.Dt_Close, W.Dt_Due, W.Subject, W.Statusid, W.Empid, W.Priorityid
         , W.Assigneeid, W.Categoryid, W.Url, W.Hrs, W.Closingnotes, W.Mins, W.Requesttypeid
      From Tbl_Webrequests W Left Join
         ( Select Reqid, Instid, Instructions
             From Tbl_Instructions I0
            Where Instid = (Select Min(Instid) From Tbl_Instructions I1
                             Where I1.Reqid = I0.Reqid)
         ) I On W.Reqid = I.Reqid
    Where W.Reqid = 319
    Order By I.Instid Asc;;)

  • Complex Multiple Table Sum Query

    Here's a doozy for you. It is a pretty large query (by my standards, anyway) that is pulling data from multiple tables to fill a GridView in ASP.NET. The query is independent of .NET, so I think this is the right place for this post.
    Summary: Trying to get all of the data from the main table and the children tables, in addition to summing up the matching values from two children tables.
    The main table is RA_INVOICES. Some of the children tables are RA_USERS, RA_STATUS, etc. The two tables I am having issues with are RA_SYSTEMINVOICES and RA_ADJUSTMENTINVOICES. The key is MAN_INVOICE_NUM. If there are no rows in either the System or Adjustment tables include MAN_INVOICE_NUM, I get nothing back from the query. Here is my current query (I removed any fields that are not joined in some way, except for the key):
    SELECT RA_INVOICES.MAN_INVOICE_NUM, RA_CURRENCIES.CURRENCY, RA_STATUS.STATUS, RA_REGIONS.REGION, RA_REASONS.REASON, RA_USERS.EMAIL AS EXPR5, RA_USERS_2.EMAIL AS EXPR4, RA_USERS_1.EMAIL, NVL(SUM(RA_SYSTEMINVOICES.SYS_INVOICE_AMT), 0) AS EXPR2, NVL(SUM(RA_ADJUSTMENTINVOICES.ADJ_INVOICE_AMT), 0) AS EXPR3
    FROM RA_INVOICES
    INNER JOIN RA_CURRENCIES ON RA_INVOICES.CURR_ID = RA_CURRENCIES.CURR_ID
    INNER JOIN RA_REASONS ON RA_INVOICES.REASON_ID = RA_REASONS.REASON_ID
    INNER JOIN RA_STATUS ON RA_INVOICES.STATUS_ID = RA_STATUS.STATUS_ID
    INNER JOIN RA_REGIONS ON RA_INVOICES.USER_GROUP_ID = A_REGIONS.REGION_ID
    INNER JOIN RA_USERS ON RA_INVOICES.CC_EMAIL_ID = RA_USERS.USER_ID
    INNER JOIN RA_USERS RA_USERS_1 ON RA_INVOICES.CCM_EMAIL_ID = RA_USERS_1.USER_ID
    INNER JOIN RA_USERS RA_USERS_2 ON RA_INVOICES.DCM_EMAIL_ID = RA_USERS_2.USER_ID
    INNER JOIN RA_SYSTEMINVOICES ON RA_INVOICES.MAN_INVOICE_NUM = RA_SYSTEMINVOICES.MAN_INVOICE_NUM
    INNER JOIN RA_ADJUSTMENTINVOICES ON RA_INVOICES.MAN_INVOICE_NUM = RA_ADJUSTMENTINVOICES.MAN_INVOICE_NUM
    GROUP BY RA_INVOICES.MAN_INVOICE_NUM, RA_CURRENCIES.CURRENCY,
    RA_STATUS.STATUS, RA_REGIONS.REGION, RA_REASONS.REASON, RA_USERS.EMAIL, RA_USERS_2.EMAIL, RA_USERS_1.EMAIL
    Optionally I need to add the following:
    HAVING (RA_INVOICES.MAN_INVOICE_NUM = 'xxxxxxxxxx')
    So... where there are values in both of the tables (System and Adjustment) for MAN_INVOICE_NUM, I get results. Otherwise, if there are no tuples exist in one or both of those tables for MAN_INVOICE_NUM, I get nothing at all.
    Sorry this is so complex. Thought I'd give you guys a good challenge. ;-)

    OK fellas (and ladies, if you happen to populate an Oracle board!)... one last question:
    The solution offered worked perfectly. I would like to see if I can accomplish one last thing with this query, and that is to do some inline math operation on the results of the query. Basically, I need to take RA_INVOICES.MAN_INVOICE_NUM and subtract SUM(NVL(RA_SYSTEMINVOICES.SYS_INVOICE_AMT, 0)) AS SYSTOTAL and SUM(NVL(RA_ADJUSTMENTINVOICES.ADJ_INVOICE_AMT, 0)) AS ADJTOTAL from it.
    I tried MAN_INVOICE_NUM - SYSTOTAL - ADJTOTAL AS TOTAL, but it returned "Error Message: ORA-00904: SYSTOTAL: invalid identifier."
    So I changed the math to say MAN_INVOICE_NUM - SUM(NVL(RA_SYSTEMINVOICES.SYS_INVOICE_AMT, 0)) - SUM(NVL(RA_ADJUSTMENTINVOICES.ADJ_INVOICE_AMT, 0)), but I am afraid of the performance implications this has... it already read the value, why should I make it do it all over again? This query will eventuall be pulling a BUNCH of rows... a year from now we'll be in the tens of thousands if the user does a global query (most of the time this query will have a WHERE statement limiting the results). Just trying to make this query as efficient as possible.
    The other alternative is to make this a SPROC. I'm clueless on SPROCS right now, but if I could gain a performance advantage using a SPROC, I'd rather do that.
    Thanks in advance for your help!

  • Urgent help needed....Query..

    Hello Experts
    Can someone help with writing a particular query. This is the test scenario
    CREATE TABLE TEST (MONTH DATE,
    AMOUNT NUMBER(17));
    INSERT INTO TEST VALUES('01-FEB-06',100);
    INSERT INTO TEST VALUES('01-MAR-06',100);
    INSERT INTO TEST VALUES('01-APR-06',100);
    INSERT INTO TEST VALUES('01-JUN-06',100);
    INSERT INTO TEST VALUES('01-JUL-06',100);
    INSERT INTO TEST VALUES('01-AUG-06',100);
    INSERT INTO TEST VALUES('01-SEP-06',100);
    INSERT INTO TEST VALUES('01-OCT-06',100);
    INSERT INTO TEST VALUES('01-NOV-06',100);
    INSERT INTO TEST VALUES('01-DEC-06',100);
    INSERT INTO TEST VALUES('01-JAN-07',100);
    INSERT INTO TEST VALUES('01-FEB-07',100);
    INSERT INTO TEST VALUES('01-MAR-07',100);
    INSERT INTO TEST VALUES('01-APR-07',100);
    INSERT INTO TEST VALUES('01-MAY-07',100);
    INSERT INTO TEST VALUES('01-JUN-07',100);
    INSERT INTO TEST VALUES('01-JUL-07',100);
    INSERT INTO TEST VALUES('01-AUG-07',100);
    INSERT INTO TEST VALUES('01-SEP-07',100);
    INSERT INTO TEST VALUES('01-OCT-07',100);
    INSERT INTO TEST VALUES('01-NOV-07',100);
    INSERT INTO TEST VALUES('01-DEC-07',100);
    INSERT INTO TEST VALUES('01-JAN-08',100);
    INSERT INTO TEST VALUES('01-FEB-08',100);
    INSERT INTO TEST VALUES('01-MAR-08',100);
    INSERT INTO TEST VALUES('01-APR-08',100);
    INSERT INTO TEST VALUES('01-MAY-08',100);
    INSERT INTO TEST VALUES('01-JUN-08',100);
    Ok so thats my test table, I want a query which will give me the sum of the field Amount grouping by Year but it should give me the sum of the month from July 06 till July 07. For Example if i put the Date Range from 2003 to 2006 then it should give me out put by group the year from july till next year jun.
    It should look something like this
    Year Amount
    07-2005/06-2006 5000
    07-2006/06-2007 2000
    07-2007/06-2008 1200
    Can i get a query which will group in the above manner???
    Thanks & Regards
    vihang

    SQL> select '07'||extract(year from add_months(month,-7))||
      2        '-07'||extract(year from add_months(month,5)) yr,
      3        sum(amount) amt
      4  from test
      5  group by '07'||extract(year from add_months(month,-7))||
      6        '-07'||extract(year from add_months(month,5));
    YR                                    AMT
    072007-072008                        1100
    072006-072007                        1200
    072005-072006                         500.
    Message was edited by:
            jeneesh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Query help from multiple tables

    I want a query from these kind of data placed in 3 different tables.
    case_batch = 2677101 , which has fine_no = 2012,2013,2014. fine_amt = 150,425,75.
    fine can be paid in cash,check or Credit card(CC)
    tble 1
    seq --- case_batch
    1 --- 2677101
    tble two
    seq -- case_batch -- fine_no -- fine_amt
    1 -- 2677101 -- 2012 -- 150
    2 -- 2677101 -- 2013 -- 425
    3 -- 2677101 -- 2014 -- 75
    tble three
    seq -- fine_no -- cash -- check -- CC
    1 -- 2012 ---- 50 -- 0 -- 0
    2 -- 2012 ---- 0 -- 50 -- 0
    3 -- 2012 ---- 0 -- 0 -- 50
    4 -- 2013 ---- 25 -- 0 -- 0
    5 -- 2013 ---- 0 -- 0 -- 400
    6 -- 2014 ---- 0 -- 0 -- 75
    I am looking for a result query like this
    case_number -- fine_no fine_amt cash check cc
    2677101 --- 2012 --- 150 --- 50 --- 50 --- 50
    --- 2013 --- 425 --- 25 --- 0 ---400
    --- 2014 --- 75 --- 0 --- 0 ----75
    2677102 etc
    hopes i made my request clear.
    appreciate all help.
    Edited by: pl/sql baby on Apr 28, 2009 10:49 AM
    Edited by: pl/sql baby on Apr 28, 2009 10:58 AM

    with t2 as (
                select 1 seq,2677101 case_batch,2012 fine_no,150 fine_amt from dual union all
                select 2 seq,2677101 case_batch,2013 fine_no,425 fine_amt from dual union all
                select 3 seq,2677101 case_batch,2014 fine_no,75 fine_amt from dual union all
                select 4 seq,2677102 case_batch,2015 fine_no,150 fine_amt from dual union all
                select 5 seq,2677102 case_batch,2016 fine_no,425 fine_amt from dual union all
                select 6 seq,2677102 case_batch,2017 fine_no,75 fine_amt from dual
         t3 as (
                select 1 seq,2012 fine_no,50 cash,0 check_,0 CC from dual union all
                select 2 seq,2012 fine_no,0 cash,50 check_,0 CC from dual union all
                select 3 seq,2012 fine_no,0 cash,0 check_,50 CC from dual union all
                select 4 seq,2013 fine_no,25 cash,0 check_,0 CC from dual union all
                select 5 seq,2013 fine_no,0 cash,0 check_,400 CC from dual union all
                select 6 seq,2014 fine_no,0 cash,0 check_,75 CC from dual union all
                select 7 seq,2015 fine_no,50 cash,0 check_,0 CC from dual union all
                select 8 seq,2015 fine_no,0 cash,50 check_,0 CC from dual union all
                select 9 seq,2015 fine_no,0 cash,0 check_,50 CC from dual union all
                select 10 seq,2016 fine_no,25 cash,0 check_,0 CC from dual union all
                select 11 seq,2016 fine_no,0 cash,0 check_,400 CC from dual union all
                select 12 seq,2017 fine_no,0 cash,0 check_,75 CC from dual
    select  case t2.fine_no when min(t2.fine_no) over(partition by t2.case_batch) then t2.case_batch end case_batch,
            t2.fine_no,
            t2.fine_amt,
            sum(cash) cash,
            sum(check_) check_,
            sum(CC) CC
      from  t2,
            t3
      where t3.fine_no = t2.fine_no
      group by t2.case_batch,
               t2.fine_no,
               t2.fine_amt
      order by t2.case_batch,
               t2.fine_no
    CASE_BATCH    FINE_NO   FINE_AMT       CASH     CHECK_         CC
       2677101       2012        150         50         50         50
                     2013        425         25          0        400
                     2014         75          0          0         75
       2677102       2015        150         50         50         50
                     2016        425         25          0        400
                     2017         75          0          0         75
    6 rows selected.
    SQL> SY.

  • Urgent Help on Dynamic Table name change in query !!!!!!!!

    Hi Everyone,
    I'm having a repeating frame which displays table_name, count_validate and count_error. How can i dynamically change my table_name in formula column apllied on count_validate and count_error. I can do this with multiple elsif statement, which makes my report slow at runtime. Select statement is same , only change is table_name ?
    Kindly let me know......

    Try to use dynamic ref cursors (defined in a database package).
    This is not exactly what you need, but see:
    "Dynamic Table in the Second Query with Oracle Reports"
    http://www.quest-pipelines.com/pipelines/plsql/tips03.htm#JULY
    Regards,
    Zlatko Sirotic

  • Table updation query

    Hi All,
    I have a table called X in that there is a field called account Number. Now i have created a table which consists of a field AccountNoRef. Now while inserting into this field a value called 0032 i need to check the table X whether that table consists the value 0032 or not. I want a procedure for thie query. Can anyone help me to do so.
    Thanking you
    Raghava

    You don't want a trigger or procedure, because it is not needed and adds additional overhead. A foreign key is all you need really:
    > I have a table called X in that there is a field called account Number.
    SQL> create table x (account_number number(5) primary key)
      2  /
    Tabel is aangemaakt.
    SQL> insert into x values (32)
      2  /
    1 rij is aangemaakt.
    > Now i have created a table which consists of a field AccountNoRef.
    SQL> create table a_table (accountnoref number(5) references x(account_number))
    2 /
    Tabel is aangemaakt.
    > Now while inserting into this field a value called 0032 i need to check the table X whether that table consists the value 0032 or not.
    SQL> insert into a_table (accountnoref) values (32)
      2  /
    1 rij is aangemaakt.
    SQL> insert into a_table (accountnoref) values (32)
      2  /
    1 rij is aangemaakt.
    SQL> insert into a_table (accountnoref) values (33)
      2  /
    insert into a_table (accountnoref) values (33)
    FOUT in regel 1:
    .ORA-02291: Integriteitsbeperking (RWIJK.SYS_C007735) is geschonden - bovenliggende sleutel is niet gevonden.No code, no complexity, just declarative integrity.
    Regards,
    Rob.

  • Need urgent help on nested tables

    Everywhere i could find a single nested table but not two. Can anyone help me on how to access and assign multi nested tables ?
    Declare
    Type a is table of varchar2(1000);
    Type b is table of a;
    v_temp b;
    Begin
    How can i assign and access variable of v_temp ?
    Please help as i can find one level nested tables examples but not this type ?
    end;

    SQL> set serveroutput on
    SQL> Declare
      2  Type a is table of varchar2(1000);
      3  Type b is table of a;
      4  v_temp b := b();
      5  Begin
      6      v_temp.extend(2);
      7      v_temp(1) := a('A','B','C');
      8      v_temp(2) := a('1','2','3','4','5');
      9      for i in 1..v_temp.count loop
    10        for j in 1.. v_temp(i).count loop
    11          dbms_output.put_line('v_temp('||i||')('||j||') = '||v_temp(i)(j));
    12        end loop;
    13      end loop;
    14  End;
    15  /
    v_temp(1)(1) = A
    v_temp(1)(2) = B
    v_temp(1)(3) = C
    v_temp(2)(1) = 1
    v_temp(2)(2) = 2
    v_temp(2)(3) = 3
    v_temp(2)(4) = 4
    v_temp(2)(5) = 5
    PL/SQL procedure successfully completed.
    SQL> SY.

  • JDBC Adapter - Multiple Table Update - Sequence Number

    I have to design a integration scenario where I will be updating 4 tables in a oracle database. One of these tables is a header table and the rest are detail tables. I have to generate a sequence number using Oracle Sequence number object which is one of the columns in the header table.
    How can i use the Oracle SEquence number object to get the next value with JDBC Adapter?

    Use an Enhancement Spot

  • Urgent help in modif table inside subroutine

    hi,
       i have written as subroutine inside it i am trying to delete from an table  contents of some fields .this table is defined in my main program whic is has an structure defined inside it
    afetr that i am passing the table to my subroutin n inside subrounti i am trying to manupulate the table contenets then i am getting the syntax erroer "table is not active or not defined in data dictonary" what wil be the cause for this..,..is there any way so thjat i can  manupulate it.???
    pls help
    points reward for useful answers
    ravi

    hi you are using Data base table commands instead of internal table commands...
    try these types:
    DATA scarr_tab TYPE SORTED TABLE OF scarr
                   WITH UNIQUE KEY carrid.
    DATA scarr_wa TYPE scarr.
    SELECT *
           FROM scarr
           INTO TABLE scarr_tab.
    READ TABLE scarr_tab INTO scarr_wa
         WITH TABLE KEY carrid = p_carrid.
    scarr_wa-currcode = 'EUR'.
    MODIFY TABLE scarr_tab FROM scarr_wa
           TRANSPORTING currcode.
    SELECT *
           FROM scarr
           INTO TABLE scarr_tab.
    READ TABLE scarr_tab
         WITH TABLE KEY carrid   = p_carrid
         TRANSPORTING NO FIELDS.
    idx = sy-tabix.
    scarr_wa-currcode = 'EUR'.
    MODIFY scarr_tab INDEX idx FROM scarr_wa
           TRANSPORTING currcode.

  • URGENT HELP:I want that the query should return in the same way

    I have a query
    select id from tableid where id in(350,241,251)
    This returns me in
    241,251,350
    I want that the query should return in the same way as specified in "in" clause.
    ie output should be in 350,241,251.
    I would really appreciate if anyone can help.

    You can achieve what you want like this:
    select id from tableid where id in (350,241,251)
    order by decode(id,350,1,241,2,251,3)in this example the decode explicitly defines the order you want to retrieve the records in.

  • Urgent help! Multiple problems.

    My iPhone 3GS screen is cracked, my lock button doesn't work even when I push the screen in, the screen loses it's touch sometimes, wont sync music, doesn't unlock sometimes, touch it slow, internet doent work sometimes, freezes a lot ect. How much will it cost to fix it? I use my phone for everything and I cant be without it for long. :/

    you could always upgrade sience you have a 3gs your probilly available for a upgrade

  • Help with a update query from a subquery

    Hello All,
    I wanted to see if someone can help me with an update query.
    I need to grab a latitude & longitude from a the same user that is in two accounts. therefore i am trying to update lat/long in a users table for one account based off of the same user in another account. I am matching the users up by phone number and last name. I tried a subquery but am having difficulty.
    I was thinking of something like the following:
    update users
    set lat = getlat, long = getlong
    inner join (select lat as getlat, long as get long from users where account_id = '1')
    on phone = phone and last name = lastname
    where account_id = '2' and lat IS NULL and long IS NULL
    Am I going in the right direction???
    Thanks in advance for any assistance!!!!

    What difficulty are you having? Have you tried what you posted and get an error?
    Although someone may be able to give you sql advice here, I would try posting this over at Stack Overflow as its not really related to Coldfusion.

Maybe you are looking for

  • Performance in plsql report

    hi guru's. i have a doubt in plsql performnace, i have been using many GTT in my project now, i feel to remove all GTT's intead of i plan to introduce collections. is it really improve the performance, i am thinking to avoid the context-switch?

  • Quicktime buffer overrun error with windows

    Hi I hope that some one out there can help me!!!! I have tried to install the new version of quicktime 7.4 but it won't install. And everytime that I try to open Quicktime player is gives me an error which reads: Buffer overrun detected! A buffer ove

  • Workflow  WS14000030 for vendor approval from OPI

    Hi,     The task TS14007942(approve creation of vendor) is included in the workflow WS14000030(Vendor One-Step Approval). Also included  the agent assignment (Rule 00000157 for Manager).   It is given in help.sap.com as below .. A vendor that has bee

  • When I playback a movie stored on Time Capsule to my Mac Book Pro the time Capsule eject 3 or 4 times during playback

    When I playback a movie stored on Time Capsule to my Mac Book Pro the time Capsule eject 3 or 4 times during playback

  • Clearing adjustments icon

    If I want to clear all History and adjustments, I know I can "Clear All" on the History but how do I clear the "Adjustments" so the little icon on the filmstrip thumbnail image (+/-) "this image has adjustments" goes away, too?