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.

Similar Messages

  • Dbms_xmlgen.newcontext query from multiple tables and ||

    I have two questions
    How do I get a dbms_xmlgen.context to query from multiple tables? I have been able to make it work with using one table only, but not with multiple tables.
    And how to get the || (concat) to work within my query for my output to an xml file?
    Here is my current query:
    create or replace function get_xml return clob is
    result clob;
    qryctx dbms_xmlgen.ctxHandle;
    SELECT DBMS_XMLGEN.getxml('select prefix, suffix, fiscal_yr
    FROM rcv.recv_accessions ra
    where ra.prefix = 8 and ra.fiscal_yr = 11')xml into result FROM dual;
    result := DBMS_XMLGEN.getXML(qryCtx);
    This is what I desire:
    SELECT DBMS_XMLGEN.getxml('select ra.prefix||'-'|| ra.suffix||'-'|| ra.fiscal_yr accession, ss.date_in, st.test
    FROM rcv.recv_accessions ra, ser.sero_samples ss, ser.sero_tests st
    where ra.prefix = 8 and ra.fiscal_yr = 11 and ss.raid = ra.id and st.ssid = ss.id')xml into result FROM dual;
    On this both the reference to multiple tables and the concat function cause errors.
    Thank you
    Edited by: user583094 on Mar 2, 2011 3:36 PM

    Hi,
    for the concat do I use xmlconcat?No, XMLConcat is used to concatenate XMLType fragments.
    The || operator will do fine, but you must escape any single quote inside the string :
    SELECT DBMS_XMLGEN.getxml(
    'SELECT ra.prefix ||''-''|| ra.suffix ||''-''|| ra.fiscal_yr as accession,
            ss.date_in,
            st.test
    FROM rcv.recv_accessions ra,
          ser.sero_samples ss,
          ser.sero_tests st
    WHERE ra.prefix = 8
    AND ra.fiscal_yr = 11
    AND ss.raid = ra.id
    AND st.ssid = ss.id'
    INTO result
    FROM dual;Or, use the quoting operator to define a custom string delimiter :
    SELECT DBMS_XMLGEN.getxml(
    q'{SELECT ra.prefix ||'-'|| ra.suffix ||'-'|| ra.fiscal_yr as accession,
            ss.date_in,
            st.test
    FROM rcv.recv_accessions ra,
          ser.sero_samples ss,
          ser.sero_tests st
    WHERE ra.prefix = 8
    AND ra.fiscal_yr = 11
    AND ss.raid = ra.id
    AND st.ssid = ss.id
    INTO result
    FROM dual;BTW, a good practice would be to use bind variables for the query. DBMS_XMLGEN can handle them nicely :
    CREATE OR REPLACE FUNCTION get_xml
    RETURN CLOB
    IS
    qryctx   DBMS_XMLGEN.ctxHandle;
    v_out    CLOB;
    qrystr   VARCHAR2(4000) :=
    'SELECT ra.prefix ||''-''|| ra.suffix ||''-''|| ra.fiscal_yr as accession,
            ss.date_in,
            st.test
    FROM rcv.recv_accessions ra,
          ser.sero_samples ss,
          ser.sero_tests st
    WHERE ra.prefix = :b_prefix
    AND ra.fiscal_yr = :b_fiscal_yr
    AND ss.raid = ra.id
    AND st.ssid = ss.id';
    BEGIN
    qryctx := DBMS_XMLGEN.newContext(qrystr);
    DBMS_XMLGEN.setBindValue(qryctx, 'b_prefix', '8');
    DBMS_XMLGEN.setBindValue(qryctx, 'b_fiscal_yr', '11');
    -- to generate empty elements if necessary :
    DBMS_XMLGEN.setNullHandling(qryctx, DBMS_XMLGEN.EMPTY_TAG);
    v_out := DBMS_XMLGEN.getXML(qryctx);
    DBMS_XMLGEN.closeContext(qryctx);
    RETURN v_out;
    END;

  • JDBC-XI-FILE scenario. How to extract data from multiple tables

    Hi,
    At this moment I didn't have the access for XI system. So here I have some silly question. Could you please clarify the same ??
    If I got to extract data from single table using JDBC adapter I can put the below query in communication channel
    SELECT *FROM orders WHERE new='true'.
    But if I got to extract data from multiple tables, logic to be used should be like as shown below. ( from previous thread------prabhu).
    SELECT <Table_2>.EID, <Table_2>.FName, <Table_2>.LName, <Table_1>.REC_DAT, <Table_1>.DESCRP
    FROM <Table_1> INNER JOIN <Table_2> on
    <Table_1>.CARDNO = <Table_2>.CARD
    where REC_DAT = <condition>
    union
    SELECT <Table_2>.EID, <Table_2>.FName, <Table_2>.LName, <Table_1>.REC_DAT, <Table_1>.DESCRP
    FROM <Table_1> INNER JOIN <Table_2> on
    <Table_1>.CARDNO = <Table_2>.CARD
    where REC_DAT = <condition>
    But my query is ........how to put the above entire code in one line. (i.e in Qery place of communication channel ) ??
    Thanks
    Kumar

    Hi Palnati,
        You either use a select query with join or a stored procedure which will contain the logic to extract the data from multiple tables. But, the limitation in case of stored procedure is u can hv only one selct query in it.
    You write ur actual query provided in the parameter 'Query SQL Statement". u can also wrt a stored procedure in it. Also, u can provide a update statement in it which will update a certain flag so tht u don selct the data again.
    Check the following link
    <a href="http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm">http://help.sap.com/saphelp_nw04/helpdata/en/14/80243b4a66ae0ce10000000a11402f/frameset.htm</a>
    Regards,
    Akshay
    Message was edited by:
            Akshay Salunke

  • Records from multiple tables

    Hi,
    I have a method that has to access records from multiple tables and store them all in a file. It's something like this:
    switch (tableId){
    case 'A' : query="SELECT * FROM TABLE_A
    WHERE ID = '" + tempId + "'";
    ResultSet rs = stmt.executeQuery (query);
    rs.close();
    break;
    case 'B' : query="SELECT * FROM TABLE_B
    WHERE ID = '" + tempId + "'";
    rs = stmt.executeQuery (query);
    rs.close();
    break;
    case 'C' : query="SELECT * FROM TABLE_C
    WHERE ID = '" + tempId + "'";
    rs = stmt.executeQuery (query);
    rs.close();
    break;
    My problem is that I get an "Invalid cursor" error the second time I enter the loop. I've been reading up on cursors but I still don't know what to do. Can I use ResultSet to return multiple rows from multiple tables? If not, what can I use? Please help!
    Thanks in advance.

    remove the "rs.close()" from the switch statement. use "rs.close()" after your loop ends.
    prem

  • Displaying data from multiple table/column

    hello ..
    anybody can help me how to diplaying data from multiple table/ column in PHP. TQ

    Follow the "How do I SELECT, INSERT, UPDATE and DELETE data from PHP?" example from http://wiki.oracle.com/page/PHP+Oracle+FAQ and change the "select ..." query to your favourite join, e.g.
    select country_name, region_name from countries, regions where countries.region_id = regions.region_id;

  • Jdbc getting data from multiple tables

    hi guys
    how can i get data from multiple tables in MSAccess
    please help

    >
    here is code thata i want to do
    i have 3 tables in my MSAccess databace
    Stud_O which consist name,surname fields
    Stud_I consist address,tel
    Stud_E department,faculty fields
    Based on this I would guess that you are missing a key field. There is no way to connect the tables.
    I make the class to insert data to the tables. But
    cant do getting datas from this tables.
    can anybody help me in making query
    and method that displays reultset strings to the
    textBoxes
    A select ...
    select name,surname from Stud_O. Use the executeQuery() method.

  • Update data provider queryspecification wiith columns from multiple tables

    Hi
    I have scenario like I need  updated a queryspecificaiton with columns from multiple tables
    1. Ex:
      <bOQuery name="Query">
              <resultObjects identifier="DS0.DO1" name="A$Application_ID"/>
              <resultObjects identifier="DS0.DO2" name="A$Column_Name"/>
    A$Application_ID is from Table A and A$Column_Name from table B
    The query is not adding to dataprovier when I am trying to updated from REST API.
    Please help me.
    Thanks
    Kalyan

    Have a look at the Business Intelligence platform RESTful Web Service Developer Guide, section 3.4.7 (p. 197) - Report structure: getting and updating the structure (specifications) of a report, may be a good place to start(?). Also see KBA 1952419 - How to update the properties of a web intelligence report using RESTful web service SDK .
    - Ludek
    Senior Support Engineer AGS Product Support, Global Support Center Canada
    Follow us on Twitter

  • Adding Sum Totals from Multiple Tables in A single Document

    Hello All,
    I'm having trouble adding sum totals from multiple tables I've created in a Pages 09 doc. I putting together a spreadsheet for cost projections for a house remodel. I created tables for each room of the house. At the bottom of the document I'd like to have another table that takes the totals from each individual room and adds them up. Problem appears to be that each table has the same x/y axis labels so row and column numbers/letters are repeated so the final table can't quantify thing correctly.
    Any easy solutions? I can't find anything that's helped in my search efforts.
    Thanks,
    Josefis

    Jerry,
    Thanks for the feedback. I thought that might be the case. And you were correct to assume I was more comfortable in Pages. I'm halfway through converting everything to numbers. In the end it will work great too. Just some different formatting/design choices to be made as numbers doesn't appear to be as versatile in the same way pages is with design. So far it looks pretty good though.
    Thanks again,
    Josefis

  • ALV for fields from multiple tables and make them editable

    Hi,
    I am working on a forecasting report. We have created few custom table e.g. store forcaset detail for whole year month wise. tables are say sales data, budget data, forcast data etc.
    Now i need to make a report based on monthwise based on above mention table.
    eg.o/p looks like:
    column name                     type desc monthapr monthmay .......
    table forcast                      Qty  sales    100          150
    table budget/sales             amt   amou    20.50    130.50
    table sales vs forcast       amt   amount  3000     50000
    -Now i don't know how to display data from multiple table in single ALV list that to with different field type.
    -2nd issue is i need to make only perticuler row editable so that user can chage data.
    -3rd when user change data and press calulate button - it should calculate data for future month - i got formula for that and disply the calulated data.
    - 4th if user like the forcast data then when press save - change data should update dbtable.
    Is this all possible with simple abap FM Or need to use ABAPOO.
    I will appericiate all expert help.
    Many thanks in advance.
    KDE.
    Edited by: kde_test on Jun 4, 2010 5:44 PM

    Hi,
    Solutions :
    1. You can use  FM REUSE_ALV_HIERSEQ_LIST_DISPLAY as guided by Ashutosh.
    You can also check out this
    [http://www.sap technical.com/Tutorials/ABAP/3DGraph/demo.htm]  change link to saptechnical without space
    2. [How to make certain rows in ALV grid editable...;
    3 & 4. Use two importing paramaters 'PF_STATUS_SET' 'USER_COMMAND' of  REUSE_ALV_GRID_DISPLAY.
    create two function codes 'CALC and 'SAVE' in pf-status and provide your required functionality to these function codes using User-Command.
    Sorry am unable to provide you with supporting code, but you can search for it and It can solve your problem
    Regards,
    Rohit

  • Delete records from multiple table

    Hi,
    I need to delete records from multiple tables using a single delete statement. Is it possible ? If so please let me know the procedure.
    Kindly Help.
    Thanks,
    Alexander.

    Hi Tim,
    Syntax of DELETE statement does not allow for multiple tables to be specified in this way. Infact, none of the DMLs allow you to specify table names like this.
    Technically, there are other ways of deleting from multiple tables with one statement.
    1. "Use a trigger":
    What was probably meant by this is that you have a driving-table on which you create a on-delete trigger. In this trigger, you write the logic for deleting from other tables that you want to delete from.
    This does mean a one-time effort of writing the trigger. But the actual DML operation of deleting from all the tables would be simply triggered by a delete on driving-table.
    2. Dynamic SQL:
    Write a PL/SQL code to open a cursor with table-names from which you want the data to be deleted from. In the cursor-for loop, write a dynamic SQL using the table-name to delete from that table.
    3. Using Foreign-Key constraint with Cascade-Delete:
    This I feel is a more 'cleaner' way of doing this.
    Having to delete data from multiple tables means that there is some kind of parent-child relationship between your tables. These relationships can be implemented in database using foreign-key constraints. While creating foreign-key constraint give the 'on delete cascade' clause to ensure that whenever data is deleted from parent-table, its dependent data is deleted from child-table.
    Using foreign-key constraint you can create a heirarchy of parent-child relationships and still your DELETE would be simple as you would only have to delete from parent-table.
    IMPORTANT: Implementing foreign-key constraints would also impact other DML operations that you should keep in mind.

  • Selecting from multiple tables, into one internal table

    Hi,
    What is the best & most efficient method of selecting from multiple table (in my case 6,) into one internal table?
    Thanks,
    John
    Points will be rewarded and all responses will be highly appreciated.

    I have simple example :
    First one - Join 5 tables
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 4 or 5 tables join.
    get run time field f2.
    f3 = f2 - f1 ( Total time).
    Second one - joins 3 table and use for all entries
    data : f1 type i,
              f2 type i,
              f3 type i.
    start-of-selection.
    get run time field f1.
    write the query 3 tables join and use for all entries
    get run time field f2.
    f3 = f2 - f1. ( Total time )
    Finally you can have time diffrence between the both sql statement.

  • ** Is it possible to give select command from multiple tables in JDBC

    Hi Friends,
    Is it possible to give the select command to select data from multiple tables directly in the 'Query SQL statement' in JDBC sender communication channel ? (Instead of Stored Procedure)
    Thanking you.
    Kind Regards,
    Jeg P.

    Hi,
    here is a sample:
    Table #1
    Header
    Name EmpId Status
    Jai 5601 0
    Karthik 5579 0
    Table #2
    Name Contactnumber
    Jai 9894268913
    Jai 04312432431
    Karthik 98984110335
    Karthik 04222643993
    select Header.Name, Header.EmpId, Item.Contactnumber from Header,Item where Header.Name = (select min(Header.Name) from Header where Header.Status = 0) and Header.Name = Item.Name
    Regards Mario

  • XDK Export in XML from multiple tables

    Hello everybody,
    I have to export data from an Oracle database to a XML file and then generate the Java classes.
    1)
    I used XSU successfully with one table. My problem is to retrieve data not from a unique table but from multiple tables linked by relations.
    I wanted to do this using XSU to retrieve data from the database and create the corresponding XML schema.
    That seems to be possible but I need help for database relations.
    Can someone help me to explain if it is possible to export from multiple tables (and if yes how)?
    2)
    Having my XML schema then I will have to generate Java objects. How is it possible with the XML Class Generator for Java?
    Does anybody have experience and samples?
    Many Thanks in advance!

    Hi Elodie,
    Please refer the Product Order sample on OTN that describes the usage of XML Class Generator for Java.
    The URL for it is:
    http://otn.oracle.com/tech/xml/xdk_sample/ProductOrdersSample.html
    Hope it helps
    Shefali

  • POWL accessing data from multiple tables/objects

    Hello,
    I have a query on the POWL applications.
    If the powl application has to access data from multiple tables/objects, then the solution would be creating a data structure of those tables/objects and referring to that structure in GET_OBJECT_DEF methods.
    Is there any other soln? or I am right here?
    The queries which are saved for a particular user are transportable? if not, how can they be made transportable?
    Thanks & regards,
    Ravish

    you are right, you can do in get_objects method.
    POWL_QUERIES are transportab;e, you can save them in POWL_QUERY transaction.
    Best regards,
    Rohit
    http://wiki.sdn.sap.com/wiki/display/WDABAP/POWL

  • JDBC outbound reading from multiple tables

    Hi,
    I have a scenario in which I have to read data from multiple tables.
    The keys of these tables (employee details) are dependent on a employee master table.
    Now there is a 1-N relationship between master and the details table. I have to send the data to an IDOC.
    I am stuck since reading from all the tables at the same time is not possible.
    Please suggest some solution.
    Thanks,
    Vaibhav

    Hi Bhavesh,
    Thanks for ur reply. It solved my problem.
    Full points to you...
    Pls help me with one more issue.
    As per the method u told i am reading from multiple tables. Each table has data for multiple employees.
    The response message is of the format
    <STATEMENT_Table1_response>
    <row>
       Data for emp 1
    </row>
    <row>
       Data for emp 1
    </row>
    </STATEMENT_Table1_response>
    <STATEMENT_Table1_response>
    <row>
       Data for emp 2
    </row>
    <row>
       Data for emp 2
    </row>
    </STATEMENT_Table1_response>
    <STATEMENT_Table2_response>
    <row>
       Data for emp 1
    </row>
    <row>
       Data for emp 1
    </row>
    </STATEMENT_Table2_response>
    <STATEMENT_Table2_response>
    <row>
       Data for emp 2
    </row>
    <row>
       Data for emp 2
    </row>
    </STATEMENT_Table2_response>
    I want to collect it to an idoc where i have data of each employee collected together. Like
    <Emp1>
      <Data from Table1>
      <Data from Table2>
    </Emp1>
    <Emp2>
      <Data from Table1>
      <Data from Table2>
    </Emp2>
    I have tried many ways and looks like a custom code in java have to written.
    Is there anything else possible?
    Thanks in Advance,
    Vaibhav

Maybe you are looking for

  • How can you get your music to download in numerical order?

    How do you get music to download in numerical order?

  • MM Business Process Flow

    Hello, Any body is having MM process flow (FLOW CHART) file. send to [email protected] Thanks in Advance. *******Poorna********

  • Reconciliation key PYPPD2012021 not defined for Payment lotf

    i am trying to post document in event 20 of FICA module  so there i am getting following error Reconciliation key PYPPD2012021 not defined for Payment lotf i am confused whether document posting is possibel in event 20 or not as the function module w

  • .m4a files and Flash

    Hi, friends. I would be grateful for any thoughts you have on this subject. The sound piece that I need to import into Flash is an .m4a file. I've never worked with that type of file and am not even sure why it is an .m4a, since all of the other soun

  • Changing the color of the  back of text

    Hi I have some text in blue and when the camera pans around the back of the text its still blue, how do i change the back color only. Thanks