using two sum() in multiple join query

Hello

I'm stuck with the help of two sum() functions in a single query. Are columns of different tables that are joined.

table of charging

Date pay_amt cust_id

1 July 13 500 1

1 July 13 200 1

amount of usage

Date usg_amt cust_id

1 July 13 100 1

2 July 13 300 2

I want a single query to give me sum (pay_amt) and sum (usg_amt) for a client in a single day

That is to say:

o/p should be:

cust_id date sum (pay_amt) sum (usg_amt)

1 01 - Jul 700 100

My query is like below. But it gives incorrect total for both. Could someone tell me why?

Select sum (pay_amt), sum (usg_amt)

from charging r

join in-house use u

On u.cust_id = r.ID_client

and you.date = r.date

where u.cust_id = 1

and you.date = 1 July 13 '

chris227 wrote:

I seem to be a bug to me.

The result is 11.2.0.3

SUM(PAY_AMT) SUM(USG_AMT)
700 200

What is your version?

What looks like the plan to explain it with predicates?

BTW, why do you think that both are incorrect, for me, only the second is incorrect, should be 200 instead of 100.

Post edited by: chris227 Question added

No Chris, the po said they want the o/p 100, and they were getting an invalid value (for example, the 200 is incorrect).

It's because of the joining of the usg_amt of duplication:

SQL > ed
A written file afiedt.buf

1 refill as (select date "'2013-07-01 as dt, 500 as pay_amt, 1 as cust_id of union double all the")
2 select dates "2013-07-01', 200, 1 double)
3, use as (select date "'2013-07-01 as dt, 100 in usg_amt, 1 as cust_id of union double all the")
4 Select the dates "2013-07-02', 300, 2 double)
5  --
6 select DT, pay_amt, usg_amt - sum (pay_amt), r.id_client, sum (usg_amt)
7 recharge r
8 join use u on u.cust_id = r.ID_client
9 and you.dt = DT
10 where u.cust_id = 1
11 * and u.dt = date ' 01-07-2013'
SQL > /.

CUST_ID DT PAY_AMT USG_AMT
---------- -------------------- ---------- ----------
1 1 JULY 2013 00:00:00 200 100
1 1 JULY 2013 00:00:00 500 100

If the sum is of course to sum up 100 twice because of two lines to pay.

So why I have indicated that the aggregation (sum) should usually before the join is made, so it is only made the cust_id amount and date for each table and then joined the results.

Tags: Database

Similar Questions

  • The call using two Business service split join in osb

    Hello

    While he was trying to call two business using Split to join the BSO I get failure message from selection in the em Bpel console. I use call activity to invoke the BS and assign to assign to the entry. the entitlement, I am assigning * $request.payload/input * to input.payload . In the em console I get entry like this


    receiveInput
    June 19, 2012 call 17:05:45 received 'process' partner 'bpelprocess1_client '.
    payload of <>
    < variableentree >
    < name of party 'payload' = >
    XXXXX < customer: process > < / customer: process >
    < / part >
    < / variableentree >
    Assign (pending)
    June 19, 2012 17:05:48 error in assessing <>expression "65 online." The result is empty for the XPath: ' / process: client / customer: entry.
    payload of <>
    xxxxxx < customer: process > < / customer: process >
    June 19, 2012 17:05:48 the following exception occurred while trying to execute the operation of copy on line 63
    payload of <>
    < bpelFault >
    < faultType > 0 < / faultType >
    < selectionFailure / >
    < / bpelFault >
    June 19, 2012 17:05:57 "BPELFault" has not been taken by a catch block.
    June 19, 2012 17:06 the transaction has been restored. Work for bpel '650002' instance has been restored, but the audit trail has been recorded for this instance. A synchronization request, please refer to the customer's request. If it is an asynchronous request, please recover from the recovery console to resend the message to invoke.


    Can anyone help on this?

    Thanks in advance...

    Hello

    I created a sample split join to assign you with a similar use cases that you tried, before the invoke activity that you call a Business Service, an activity Assign Action and write the payload of body in the field of expression and in the variable field, I chose my input activity Invoke variable which is InvokeInput.payload.

    Payload body I pasted in the expression field looks to...

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

    Input samples

    -----------

    Hope this helps,
    N

  • Left join between two tables using two different conditions

    I have following three tables with their data, as shown below.

    CREATE TABLE TIREMASTERPROCESS_TEMP
    (
    PRODUCTIONCODE TANK (12 BYTES),
    FIELDNAME CHAR (12 BYTES),
    DATACHR VARCHAR2 (60 BYTE),
    REVISIONNO TANK (3 BYTES),
    DATANUM NUMBER (9.4)
    )
    Whether the table c. and its sample data are like

    FIELDNAME DATACHR REVISIONNO DATANUM PRODUCTIONCODE
    AB No. Nch 1 100 0
    AB No. Nch 1 108 0
    AB No.-of-Nch 1 1 0
    Ass42 teased dishes 1 0
    Ass42 BTDrumNo1 BTD-051 1 0
    AB53 BTDrumNo1 BTD-051 104 0


    CREATE TABLE materialcode
    (
    UPPERMATERIALCODE CHAR (20),
    PROCESSNO TANK (3),
    PROCESSADOPTDATE TANK (9)

    )
    Whether the table b. and its sample data are like

    UPPERMATERIALCODE PROCESSNO PROCESSADOPTDATE
    Ass42 1 20120717
    AB53 108 20121121
    111 20111104 AS05
    104 20120928 AS30


    CREATE TABLE BUILDINGSCHEDULEMASTER
    (
    BUILDINGSIZE TANK (5 BYTES),
    GTCODE FLOAT (4 BYTES),
    TIREPERCART NUMBER (3.0).
    BUILDINGLOT NUMBER (3.0)
    )
    Whether table and its sample data are like

    BUILDINGSIZE GTCODE TIREPERCART BUILDINGLOT
    AB42A 4 12 ass42
    AB53A 4 88 AB53
    AS30A AS30 4 80
    BF03A 1 90 BF03


    Now, I need to get some data in these fields by using the suite of mappings.

    « PR_ » || Trim (a.BUILDINGSIZE) | ' / MPL2' Processid,--PRIMARY KEY
    TO_DATE (substr (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') starteff, to_date (SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 7, 2) |) » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 5, 2) | » /'|| SUBSTR (NVL(b.PROCESSADOPTDATE,'19800101'), 1, 4). (' 01:00:00 ',' dd-mm-yyyy hh24:mi:ss') startDate.
    b.PROCESSNO revisioncodeid,
    a.BUILDINGLOT tirepercart ,
    CASE WHEN c.FIELDNAME = 'BTDrumNo1' then c.DATACHR end drumtype1.
    BOX WHEN (trim (C.DATACHR) = '1' and trim (C.FIELDNAME) = "No. Nch") and THEN click 'YES '.
    ANOTHER 'NO '.
    END may-BUG,
    case
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR = 'Use' THEN on 'YES '.
    When c.FIELDNAME = 'Wavy'
    AND c.DATACHR <>'Use' THEN 'NO '.
    fine wavy


    Now for the tables A and B I have the simple join as condition

    a.GTCODE = b.UPPERMATERIALCODE

    But I have to use two different left join conditions to join the table B and C to calculate the RESP fields according to the condition.
    Now, I have to use

    (trim (b.UPPERMATERIALCODE)). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    condition to get the data for the WAVY and DRUMTYPE1 fields.

    But at the same time, I have to use

    substr (Trim (b.UPPERMATERIALCODE), 1, 2). » -'|| Trim (b.PROCESSNO) = Trim (c.PRODUCTIONCODE) | » -'|| Trim (c.REVISIONNO)

    conition to derive the CHAFER field.

    And for this reason I am come so many duplicates and do not correct results for JUNEBUG, WAVY, DRUMTYPE1, and STARTDATE field.

    I need some advice as how can I do so that I get the correct results without duplicates for the PRIMARY KEY.

    Thank you

    Mahesh

    It would have been easier to answer if you gave us your example query that gives incorrect results - which both show us what you are doing and give us a starting point.
    Insert instructions for data, rather than only the data would have helped too, making it more quick to test this point.
    You do not show what you have done with your two outer join criteria, but I think you need to list TIREMASTERPROCESS_TEMP in your query twice, with alias names. Here's what I did:

    select a.BUILDINGSIZE, a.GTCODE, b.PROCESSNO ,  c1.FIELDNAME, c1.DATACHR, C2.FIELDNAME, C2.DATACHR
    , CASE WHEN c1.FIELDNAME='BTDrumNo1' then c1.DATACHR end drumtype1
    , CASE WHEN (trim(c2.DATACHR) = '1' and trim(c2.FIELDNAME) = 'No-of-Nch') THEN 'YES' ELSE 'NO' END CHAFER
    , case when c1.FIELDNAME='Wavy' AND c1.DATACHR='Use' THEN 'YES'
           when c1.FIELDNAME='Wavy' then 'NO' else null end wavy
    from BUILDINGSCHEDULEMASTER        A
    join materialcode b on a.GTCODE=b.UPPERMATERIALCODE
    left outer join TIREMASTERPROCESS_TEMP c1
       ON trim(b.UPPERMATERIALCODE)||'-'||trim(b.PROCESSNO) = trim(c1.PRODUCTIONCODE)||'-'||trim(c1.REVISIONNO)
    left outer join TIREMASTERPROCESS_TEMP c2
       ON substr(trim(b.UPPERMATERIALCODE),1,2)||'-'||trim(b.PROCESSNO) = trim(c2.PRODUCTIONCODE)||'-'||trim(c2.REVISIONNO)
    

    C1 is an alias for the TIREMASTERPROCESS_TEMP line which is necessary for drumtype1 and wavy, c2 is an alias for the TIREMASTERPROCESS_TEMP line required for JuneBug. There was some minor errors in your calculations of field I tried to correct.

    The results are:

    BUILD GTCO PRO FIELDNAME    DATACHR    FIELDNAME    DATACHR    DRUMTYPE1  CHA WAV
    ----- ---- --- ------------ ---------- ------------ ---------- ---------- --- ---
    AB53A AB53 108                         No-of-Nch    1                     YES
    AB42A AB42 1   BTDrumNo1    BTD-051    No-of-Nch    1          BTD-051    YES
    AB42A AB42 1   Wavy         NotUse     No-of-Nch    1                     YES NO
    AS30A AS30 104                                                            NO
    

    Hope this helps,
    David

  • How can I perform this type of beach using DPL join query?

    How can I perform this type of beach using DPL join query?

    SELECT * from t where 1 < = t.a < = 2 and 3 < = t.b. < = 5

    In this pdf file: http://www.oracle.com/technology/products/berkeley-db/pdf/performing%20queries%20in%20oracle%20berkeley%20db%20java%20edition.pdf,

    It shows how to perform "Two motion equal on a single primary database" like SELECT * TAB WHERE A = col1 AND col2 = B using the join entity class, but it does not give a solution on the range join query.

    Right, you can only use an index for this query. If you do not need another index for another query, you might fall (remove @SecondaryKey).

    -mark

  • How it warns Oracle to use an index for the join of two tables...

    How to prevent the Oracle to use an index for the join of two tables to get a view online that is used in an update statement?

    O.K. I think I should explain what I mean:

    When you join two tables that have many entries sometimes there're better is not to use an index on the column that is used as a criterion to join.

    I have two tables: table A and table B.

    Table A has 4,000,000 entries and table B has 700,000 entries.

    I have a join of two tables with a numeric column as join criteria.

    There is an index on this column in A table.

    So I instead of
      where (A.col = B.col)
    I want to use
      where (A.col+0 = B.col)
    in order to avoid Oracle using the index.

    When I use the join in a select query, it works.

    But when I use the join as inline in an update statement I get the error ORA-01779.

    When I remove the '+ 0' the update statement works. (The column is unique in table B).

    Any ideas why this happens?

    Thank you very much in advance for any help.

    Hartmut cordially

    You plan to use a NO_INDEX hint as shown here: http://www.psoug.org/reference/hints.html

  • Left join of the two tables and multiple values into a single value separated by commas

    Hello

    I have following tables with their structures and their data as below.

    CREATE TABLE 'BETODI '. "" BETINFO ".

    (

    VARCHAR2 (8 BYTE) "CURRENTPRESS."

    ENABLE 'TYPEIDCONTAINER' VARCHAR2 (30 BYTE) NOT NULL

    )

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24D', 'Pensky-MARTENS');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A25D", "CMP");

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A25G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26D', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26G', 'PMC');

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A32G", "V-BFC3");

    INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A32D', "V-BFC2");

    CREATE TABLE 'BETODI '. "" BETMASTER ".

    (

    ACTIVATE THE "CUREPRESS" TANK (5 BYTES) NOT NULL,

    ACTIVATE THE "TYPE" VARCHAR2 (5 BYTE) NOT NULL,

    NUMBER (5.0) "LASTPCIRIM".

    )

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A24', '45 M 8', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A25', 42 16', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A26", 16' 45, 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A27", '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A28', '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A29', '45 M 34', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A30', '45MCH', 15);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A31", "45MCH", 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A32', '45MCH', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A33', '45MCH', 16);

    INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A34", "45MCH", 16);

    These two tables have left join as

    BETMASTER. CUREPRESS = substr (BETINFO. CURRENTPRESS, 1, 3)

    now I want to have the data in the two tables with fields Curepress, Lastpcirim, typeidcontainer.

    Also something like

    Make a group of typeidcontainer if this value is greater than 1 by press separated the values of semicolon (;)

    So, for example above, we should be given as

    A24 PMC 15; PENSKY-MARTENS

    A25 15 PMC

    A26 15 PMC

    A27 16 (NULL)

    A28 16 (NULL)

    A30 15 (NULL)

    A31 16 (NULL)

    A32 16 BFC2-V; V BFC3

    A33 16 (NULL)

    A34 16 (NULL)

    How could do?

    My current request is as

    Select distinct Curepress, lastpcirim, typeidcontainer

    BETMASTER STD left join INF BETINFO

    on the trim (STD. CUREPRESS) = substr (trim (INF. CURRENTPRESS), 1, 3)

    but I am unable to get the values separated by commas.

    Any help would be appreciated.

    Thank you

    Mahesh.

    Hi, Mahesh,

    If you want to only 1 row of output for each distinct combination of currentpress and lastpcirim?  This sounds like a job for GROUP BY.

    And you want the row to contain a list of all different typidcontainers-delimited?  This sounds like a job for the aggregate LISTAGG function.

    WITH joined_data AS

    (

    SELECT DISTINCT

    MST.curepress, mst.lastpcirim, inf.typeidcontainer

    OF betmaster STD

    LEFT JOIN betinfo ON TRIM (mst.curepress) inf = SUBSTR (TRIM (inf.currentpress)

    1

    3

    )

    )

    SELECT curepress, lastpcirim

    LISTAGG (typeidcontainer, ',')

    THE Group (ORDER BY typeidcontainer) AS container_list

    OF joined_data

    Curepress GROUP, lastpcirim

    ;

    Unfortunately, you can't say LISTAGG (DISTINCT ...), so you should always get the separate containers how you already are.  (Note that the subquery is just what you posted).

    Thanks for posting the CREATE TABLE and INSERT statements; It is very useful.  Don't forget to tell what version of Oracle you are using.  LISTAGG was new in Oracle 11.2.

    Why not add CHECK constraints (and perhaps triggers) to your tables, so that curepress and currentpress are not stored with the head or trailing spaces?  Then you wouldn't need to use the PAD in queries like this, and your code would be simpler and more effective.

  • Left outer join query and check the status

    Hello

    I have two tables as tables below

    table_1

    MI_ACC_IDENTIFIERCHARGE_START_DATECHARGE_END_DATEPBA_INT_AMT
    200000000001 SEP-05 00.00.0029 SEP-05 00.00.000.26
    200000000030 SEP-05 00.00.0031 OCTOBER 05 00.00.001.92
    20000000001 NOVEMBER 05 00.00.00NOVEMBER 30 05 00.00.000.34
    20000000001 AUGUST 06 00.00.0031 AUGUST 06 00.00.000.47
    200000000031 MARCH 06 00.00.0027 APRIL 06 00.00.000.34
    200000000030 DECEMBER 05 00.00.0031 JANUARY 06 00.00.001.92
    20000000001 MARCH 05 00.00.0031 MARCH 05 00.00.000.26

    Table_2

    MI_ACC_IDENTIFIERCHARGE_START_DATECHARGE_END_DATETOT_INT_AMT_OVER_25P
    200000000030 SEP-05 00.00.0031 OCTOBER 05 00.00.000
    20000000001 NOVEMBER 05 00.00.00NOVEMBER 30 05 00.00.000.81756
    20000000001 DECEMBER 05 00.00.0029 DECEMBER 05 00.00.000.64724
    200000000030 DECEMBER 05 00.00.0031 JANUARY 06 00.00.005.51555

    Power required:

    MI_ACC_IDENTIFIERCHARGE_START_DATECHARGE_END_DATENVL(B.PBA_INT_AMT,0)TOT_INT_AMT_OVER_25P
    20000000001 NOVEMBER 05 00.00.00NOVEMBER 30 05 00.00.000.340.81756
    200000000030 DECEMBER 05 00.00.0031 JANUARY 06 00.00.001.925.51555
    20000000001 DECEMBER 05 00.00.0029 DECEMBER 05 00.00.0000.64724

    I have to check if TOT_INT_AMT_OVER_25P > B.PBA_INT_AMT and also required to display if there is no matching record in table_1 and exist in table_2 then display as well

    Queries for the table:

    CREATE TABLE 'TABLE_1 '.

    (

    ACTIVATE THE "MI_ACC_IDENTIFIER" NUMBER (10,0) NOT NULL,

    DATE OF THE "CHARGE_START_DATE."

    DATE OF THE "CHARGE_END_DATE."

    NUMBER (15.2) "PBA_INT_AMT".

    );

    Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date ('01 - SEP - 05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (29-SEP-05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.26);

    Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (30-OCT-05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (31 October 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 1.92);

    Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (1 November 05 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (30 November 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.34).

    Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (1 August 06 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (31 August 06 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.47);

    Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (31 March 06 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (27 April 06 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.34).

    Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (30 December 05 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (31 January 06 00.00.00','DD-MON-RR HH24.MI.) SS'), 1.92);

    Insert into TABLE_1 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, PBA_INT_AMT) values (2000000000, to_date (1 March 05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (31 March 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.26);

    CREATE TABLE 'TABLE_2.

    (

    ACTIVATE THE "MI_ACC_IDENTIFIER" NUMBER (10,0) NOT NULL,

    DATE OF THE "CHARGE_START_DATE."

    DATE OF THE "CHARGE_END_DATE."

    "TOT_INT_AMT_OVER_25P" NUMBER (15.5)

    );

    Insert in TABLE_2 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, TOT_INT_AMT_OVER_25P) values (2000000000, to_date (30-OCT-05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (31 October 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0);

    Insert in TABLE_2 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, TOT_INT_AMT_OVER_25P) values (2000000000, to_date (1 November 05 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (30 November 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.81756);

    Insert in TABLE_2 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, TOT_INT_AMT_OVER_25P) values (2000000000, to_date (1 December 05 00.00.00','DD-MON-RR HH24.MI.)) SS'), to_date (29 December 05 00.00.00','DD-MON-RR HH24.MI.) SS'), 0.64724);

    Insert in TABLE_2 (MI_ACC_IDENTIFIER, CHARGE_START_DATE, CHARGE_END_DATE, TOT_INT_AMT_OVER_25P) values (2000000000, to_date (30 December 05 00.00.00','DD-MON-RR HH24.MI.)) To_date SS'), (31 January 06 00.00.00','DD-MON-RR HH24.MI.) SS'), 5.51555);

    Query, I used:

    SELECT A.MI_ACC_IDENTIFIER, A.CHARGE_START_DATE, A.CHARGE_END_DATE, NVL (B.PBA_INT_AMT, 0), a.TOT_INT_AMT_OVER_25P OF
    TABLE_2 A, B FROM TABLE_1
    WHERE A.MI_ACC_IDENTIFIER = B.MI_ACC_IDENTIFIER (+)
    AND A.CHARGE_START_DATE = B.CHARGE_START_DATE (+)
    AND A.CHARGE_END_DATE = B.CHARGE_END_DATE (+)
    and A.TOT_INT_AMT_OVER_25P > B.PBA_INT_AMT (+);

    I have been using the syntax of ANSI join for some time. They are readable and code looks more elegant. A reason do not want to use it?

    I don't care

    SQL> select t2.mi_acc_identifier
      2       , t2.charge_start_date
      3       , t2.charge_end_date
      4       , nvl(t1.pba_int_amt, 0) pba_int_amt
      5       , t2.tot_int_amt_over_25p
      6    from table_1 t1
      7       , table_2 t2
      8   where t1.mi_acc_identifier (+)= t2.mi_acc_identifier
      9     and t1.charge_start_date (+)= t2.charge_start_date
     10     and t1.charge_end_date   (+)= t2.charge_end_date
     11     and (t1.pba_int_amt < t2.tot_int_amt_over_25p     or t1.mi_acc_identifier is null);
    
    MI_ACC_IDENTIFIER CHARGE_ST CHARGE_EN PBA_INT_AMT TOT_INT_AMT_OVER_25P
    ----------------- --------- --------- ----------- --------------------
           2000000000 01-NOV-05 30-NOV-05         .34               .81756
           2000000000 30-DEC-05 31-JAN-06        1.92              5.51555
           2000000000 01-DEC-05 29-DEC-05           0               .64724
    
    SQL>
    
  • Using the index of multiple values

    Hi guys,.

    Trying to assess the benefits of the addition of index of multiple values, a quick question on the index of multiple values:

    Here's my content from the cache:

    Key (EmpID), value [employee (age int, double salary, Department of String)]
    (1, new employee (25, 35000.0, "Admin"));
    (2, new employee (22, 30000.0, "Admin"));
    (3, new employee (34, 40000.0, 'Communications'));
    (4, new employee (36, 41000.0, "Admin"));
    (5, new employee (36, 42000.0, "HR"));
    (6, new employee (29, 30000.0, "HR"));
    (7, new employee (51, 50000.0, "BackOffice"));
    (8, new employee (36, 35000.0, "HR"));
    (9, new employee (46, 45000.0, "Admin"));
    (10, new employee (48, 47000.0, "HR"));

    If I still want to find all employees in the 'Human resources' Department and whose salary is more than 35000.

    Eventually, I would like to do the following:
    ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
    ValueExtractor depExtractor = new PofExtractor (String.class, 3);
    cache.addIndex (salExtractor, false, null);
    cache.addIndex (depExtractor, false, null);

    EqualsFilter departmentFilter = new EqualsFilter (depExtractor, 'HR');
    GreaterFilter salFilter = new GreaterFilter (salExtractor, 35000);
    Filter allFilter = new AllFilter (new filter [] {departmentFilter, salFilter});
    Employees value = cache.entrySet (allFilter));

    For my usecase above how can I use the indexing of multiple values to the same query?
    ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
    ValueExtractor depExtractor = new PofExtractor (String.class, 3);
    MultiExtractor mExtractor is new MultiExtractor (new ValueExtractor [] {salExtractor, depExtractor});.
    cache.addIndex (mExtractor, false, null);

    But how can I use the extractor to create multivalued filter queries for employees in the Department of human resources with greater than 35000 salary? Any ideas are much appreciated.


    Thank you

    D wrote:
    Hi guys,.

    Trying to assess the benefits of the addition of index of multiple values, a quick question on the index of multiple values:

    Here's my content from the cache:

    Key (EmpID), value [employee (age int, double salary, Department of String)]
    (1, new employee (25, 35000.0, "Admin"));
    (2, new employee (22, 30000.0, "Admin"));
    (3, new employee (34, 40000.0, 'Communications'));
    (4, new employee (36, 41000.0, "Admin"));
    (5, new employee (36, 42000.0, "HR"));
    (6, new employee (29, 30000.0, "HR"));
    (7, new employee (51, 50000.0, "BackOffice"));
    (8, new employee (36, 35000.0, "HR"));
    (9, new employee (46, 45000.0, "Admin"));
    (10, new employee (48, 47000.0, "HR"));

    If I still want to find all employees in the 'Human resources' Department and whose salary is more than 35000.

    Eventually, I would like to do the following:
    ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
    ValueExtractor depExtractor = new PofExtractor (String.class, 3);
    cache.addIndex (salExtractor, false, null);
    cache.addIndex (depExtractor, false, null);

    EqualsFilter departmentFilter = new EqualsFilter (depExtractor, 'HR');
    GreaterFilter salFilter = new GreaterFilter (salExtractor, 35000);
    Filter allFilter = new AllFilter (new filter [] {departmentFilter, salFilter});
    Employees value = cache.entrySet (allFilter));

    For my usecase above how can I use the indexing of multiple values to the same query?
    ValueExtractor salExtractor = new PofExtractor (Integer.class, 2);
    ValueExtractor depExtractor = new PofExtractor (String.class, 3);
    MultiExtractor mExtractor is new MultiExtractor (new ValueExtractor [] {salExtractor, depExtractor});.
    cache.addIndex (mExtractor, false, null);

    But how can I use the extractor to create multivalued filter queries for employees in the Department of human resources with greater than 35000 salary? Any ideas are much appreciated.

    Thank you

    I remember, values multiple index refers to a different concept: a multivalued index means that you can retrieve a collection of values of similar role of an attribute on which you can do Contains, ContainsAll filtering, and ContainsAny.

    In this case to fully the lever consistency of querying capabilities, you would
    - either add a sorted index with a custom comparator that compares the tables containing a salary and a Department on a first salary so the base of the Department and add a filter custom which is able to take advantage of the index for the request for the salary and also able to filter on the element of the array of index service
    -Add two independent indices (a sorted index of wages and a unsorted for the Department), in which case you can leverage all existing (GreaterThanFilter, EqualsFilter and AndFilter) code

    Best regards

    Robert

  • problem of multiple join

    I know there are issues using multiple joins in access, however I have three tables that use 'custno' as a key and I need to recover data from all three. Is there a way to do this? I get the following error:

    Run database query error.
    [Macromedia] [SequeLink JDBC Driver] [ODBC Socket] [Microsoft] [ODBC Microsoft Access driver] The specified field 'custno' may designate more than one table listed in the FROM clause in the SQL statement.

    Here is my SQL:

    < CFQUERY NAME = "qryGetOrders" DATASOURCE = "mcc" >
    SELECT custno, orderno, itemno, quantity, truck, deliverydate, orderdate, field3, company
    OF dailyorders, OrderRegister, arinvt01, arcusto
    WHERE dailyorders.custno = OrderRegister.custno AND dailyorders.itemno = arinvt01.field1 AND dailyorders.custno = arcusto.custno
    ORDER BY dailyorders.orderno
    < / CFQUERY >

    You must qualify the name of each column by its table name (or alias).

    See attachment.

  • OUTER JOIN query returns the results of JOIN IN-HOUSE 11.2.0.1.0

    I'm data transfer in 11.2.01.0 (Windows XP 32-bit) and I wanted to compare the sizes of table with the same Table name in two different patterns, ML and SILENT, with a FULL OUTER JOIN (to account for all the tables and NULL values in a diagram).

    The scheme of ML has 176 tables: schema TUT a 133 tables. The use of a standard INNER JOIN gives 131 paintings.

    I get precisely the results with a FULL OUTER JOIN I get with an INTERNAL JOIN (not the same NULL values so I know they exist).

    This happens in SQL-Plus, SQL_Developer and using Oracle Wire pilot of Data_Direct.

    Here is the code:

    Login: SYS as SYSDBA or SYSTEM (same results for either)

    SELECT M.TABLE_NAME, M.NUM_ROWS, T.TABLE_NAME, T.NUM_ROWS
    OF SYS. ALL_TABLES M FULL OUTER JOIN SYS. ALL_TABLES T ON M.TABLE_NAME = T.TABLE_NAME
    WHERE
    M.OWNER = 'ML' AND
    T.OWNER = 'TUT';

    Produce the same results with LEFT OUTER joins and RIGHT OUTER joins in ASI and Oracle (+) syntax.

    Any thoughts?

    Hello

    If you read what I posted, forget it. MScallion (below) gave the correct answerr.

    If conditions such as

    owner   = 'ML'
    

    in the WHERE clause, and then they will reject the rows of the result set formed by the join condition.

    The inner join returns only 131 lines where the two 'paintings' have the same table_names.
    The outer joins return multiple lines (133, 176 or 178) before the place WHERE the provision is applied , but the WHERE clause eliminates all lines except the 131 found by the inner join.

    Published by: Frank Kulash, July 10, 2010 14:23

  • Left join with three-table join query

    I am trying to create a query that left me speechless. Most of the query is simple enough, but I have a problem I do not know how to solve.

    Background:
    We have stock stored in i_action.

    We have the attributes available for each type of action. The attributes available for each action are described in shared_action_attribute. Each type of action can have three attributes or none at all.

    We have the values stored for the attributes in i_attribute_value.

    An example says:
    We have a transfer action (action_code B4). The action of B4 entry into i_action records the fact that the transfer took place and the date at which he spoke. The attributes available for a transfer action are the function code receiver, the receiving unit number and the reason of transfer code. These types of attributes available and their order are stored in shared_action_attribute. The actual values of the attributes for a specific action of transfer are stored in i_attribute_value.

    Now i_action and i_attribute_value can be connected directly in action_seq in i_action and ia_action_seq in i_attribute_value. A left join on these two tables provides results for all actions (including actions that have no attributes) and assign values (see Query 1 below).

    There are two questions. First of all, I want only the first two attributes. To specify the attributes of the first two, I also i_attribute_value a link to shared_action_attribute (which is where the order is stored). I can build a simple query (without the left join) which connects the three tables, but then shares without attributes would be excluded from my result (see Query 2 below).

    The second problem is that I'd actually a row returned for each action with first_attribute and second_attribute in the form of columns instead of two lines.

    The final query will be used to create a materialized view.

    Here are the tables and examples of what is stored in the:

    TABLE i_action
    Name Type
    ----
    ACTION_SEQ NUMBER (10)
    DATE OF ACTION_DATE
    ACTION_CODE VARCHAR2 (3)
    VARCHAR2 (1) DELETED

    EXAMPLE OF LINES
    ACTION_SEQ ACTION_DATE DELETED ACTION_CODE
    ----
    45765668 9 OCTOBER 09 B2 HAS
    45765670 9 OCTOBER 09 BA HAS
    45765672 B6 9 OCTOBER 09A
    45765673 9 OCTOBER 09 B4 HAS
    45765674 9 OCTOBER 09 G1 HAS
    45765675 9 OCTOBER 09 M3 HAS

    TABLE i_attribute_value
    Name Type
    ---
    IA_ACTION_SEQ NUMBER (10)
    SACTATT_SACT_CODE VARCHAR2 (3)
    SACTATT_SAT_TYPE VARCHAR2 (3)
    VARCHAR2 VALUE (50)

    EXAMPLE OF LINES
    IA_ACTION_SEQ SACTATT_SACT_CODE SACTATT_SAT_TYPE VALUE
    ----
    45765668 B2 COA 37 B
    45765670 BA ROA D
    45765670 BA ROR P
    45765672 B6 CAT C
    B4 45765673 RFC E
    45765673 B4 TRC P
    B4 45765673 RUN 7
    45765674 G1 SS 23567
    G1 45765674 ASG W

    TABLE shared_action_attribute
    Name Type
    ---
    SACT_CODE VARCHAR2 (3)
    SAT_TYPE VARCHAR2 (3)
    ORDER NUMBER (2)
    TITLE VARCHAR2 (60)

    EXAMPLE OF LINES
    SACT_CODE SAT_TYPE UNDER THE ORDER
    ----
    B2 ACO 1 Office code
    BA ROR 1 reason to re-open
    Authority of BA ROA 2 reopen
    B6 CAT 1 category
    B4 RFC 1 reception function code
    B4 RUN 2 receives the unit code
    B4 TRC 3 transfer of reason code
    Sequence of G1 SS 1 personal
    Reason for G1 ASG 2 assignment

    QUERY 1:
    It's my current query as well as its results. Most are select simple but only one column is filled using the function analytic last_value (thank you guys). The last column in the view sub stores the value of the attribute. What I want is to replace this single column with two columns named first_attribute and second_attribute and eliminate all other attributes.
    SELECT ia.action_seq, ia.action_date, ia.action_code cod,
    NVL
    (LAST_VALUE (CASE
    WHEN ia.action_code = "G1".
    AND iav.sactatt_sat_type = 'SS '.
    THEN THE VALUE
    WHEN ia.action_code IN ('A0', 'A1')
    THEN '67089'
    END IGNORE NULLS
    ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
    IA.serial_number, ia.action_seq),
    '67089'
    ) staff_seq,.
    value
    From i_action LEFT JOIN i_attribute_value iav AI
    ON iav.ia_action_seq = ia.action_seq
    WHERE ia.deleted = 'A ';

    ACTION_SEQ ACTION_DA COD STAFF_SEQ VALUE
    ----
    45765668 9 OCTOBER 09 B2 67089 37 B
    45765670 9 OCTOBER 09 BA D 67089
    45765670 9 OCTOBER 09 BA 67089 P
    45765672 9 OCTOBER 09 B6 67089 C
    45765673 9 OCTOBER 09 B4 67089 E
    45765673 9 OCTOBER 09 B4 67089 P
    45765673 9 OCTOBER 09 67089 7 B4
    45765674 9 OCTOBER 09 23567 23567 G1
    45765674 9 OCTOBER 09 G1 23567 W
    45765675 9 OCTOBER 09 M3 23567

    QUERY 2:
    This query is limited to the first two attributes but he also filed actions which have no attributes, and it creates still several lines for each action instead of a single line with two columns for attributes.
    SELECT ia.action_seq, ia.action_date, ia.action_code cod,
    NVL
    (LAST_VALUE (CASE
    WHEN ia.action_code = "G1".
    AND iav.sactatt_sat_type = 'SS '.
    THEN THE VALUE
    WHEN ia.action_code IN ('A0', 'A1')
    THEN '67089'
    END IGNORE NULLS
    ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date,
    IA.serial_number, ia.action_seq),
    '67089'
    ) staff_seq,.
    value
    OF shared_action_attribute saa, ims_action AI, ims_attribute_value iav
    WHERE iav.ia_action_seq = ia.action_seq
    AND iav.sactatt_sact_code = saa.sact_code
    AND iav.sactatt_sat_type = saa.sat_type
    AND saa.display_order IN ('1 ', ' 2')
    AND ia.deleted = 'A ';

    ACTION_SEQ ACTION_DA VALUE OF COD
    ----
    45765668 9 OCTOBER 09 B2 67089 37 B
    45765670 9 OCTOBER 09 BA D 67089
    45765670 9 OCTOBER 09 BA 67089 P
    45765672 9 OCTOBER 09 B6 67089 C
    45765673 9 OCTOBER 09 B4 67089 E
    45765673 9 OCTOBER 09 67089 7 B4
    45765674 9 OCTOBER 09 23567 23567 G1
    45765674 9 OCTOBER 09 G1 23567 W

    I found it quite complex to try to write - I hope that I was clear.

    Thank you very much!

    Hello

    You can use an alias for column (such as staff_seq) in the ORDER BY. Unfortunately, it's the only place where you can use it in the same query, where it was defined.
    You can use it anywhere in the super-requetes, however, so you can still work around this problem in assigning the aliases in a subquery and GROUP BY (or other) in a Super query, like this:

    WITH   ungrouped_data      AS
    (
        SELECT ia.action_seq, ia.action_date, ia.action_code,
              NVL
                  (LAST_VALUE (CASE
                                  WHEN ia.action_code = 'G1'
                                   AND sactatt_sat_type = 'SS'
                                     THEN VALUE
                                  WHEN ia.action_code IN ('A0', 'A1')
                                     THEN '67089'
                               END IGNORE NULLS
                              ) OVER (PARTITION BY ia.ici_charge_inquiry_seq ORDER BY ia.action_date, ia.action_seq),
                   '67089'
                  )staff_seq,
               (CASE
                  WHEN display_order = '1'
                  THEN VALUE
               END) first_attribute,
               (CASE
                  WHEN display_order = '2'
                  THEN VALUE
               END) second_attribute
          FROM i_action ia
          LEFT JOIN i_attribute_value iav
               ON iav.ia_action_seq = ia.action_seq
          LEFT JOIN shared_action_attribute
               ON sactatt_sact_code = sact_code
             AND sactatt_sat_type = sat_type
         WHERE ia.deleted = 'A'
    )
    SELECT       action_seq
    ,       action_date
    ,       action_code
    ,       staff_seq
    ,       MIN (first_attribute)          AS first_attribute
    ,       MIN (second_attribute)     AS second_attribute
    FROM       ungrouped_data
    GROUP BY  action_seq
    ,       action_date
    ,       action_code
    ,       staff_seq
    ;
    

    There are other alternatives for special cases, but none of them work in this particular case.

  • Avoid the multiple join

    Hi all

    How can we avoid multiple join for queries like this

    Select temp1 a, temp1 a.x, b.x, c.text a, c to temp2 where a.y = c.y and b.y = c.z

    So, it will scan temp1 twice. Can we do this to analyze only once

    application of warehouse that joins the tables more then 5-6

    Well, it certainly changes the circumstances ;)
    However: put you it in a small testcase, everyone can play and test with, thanks for this anyway.

    If am understanding right

    What I wanted to point out, is that you will need to run tests on your own configuration (equipment/sets/distribution, etc.)
    My little test notes (on my setup, which is not a warehouse at ;)) there's still nothing wrong with a full table scan + hash join.) It would be 'better' in 'my cases '.
    But "your case" is quite different.
    One thing I do know of: your hardware will be better than my old Windoze pc by orders of magnitude.
    Optimizer considers several aspects (selectivity of cpu/data etc.) that will completely differ from my plans.
    You should compare the different options you have in tracing the respective motions, you think that you could use, each of them and compare the results you get. Choose the one that suits.
    So: you are about to go to the next level:
    Always test and measure these things, different scenario that are available.
    As there is no generic datamodel, it is not a generic 'alter system set fast = true' option (yet).
    Optimizer tries to keep track of each scheme and did the best that he can do, but it's also been polished every version.
    Therefore: never take results things for granted.
    Now I could say, just as everyone else: 'approach 'A' works better. Period. "(And create a"Silver Bullet"myth and selling lots of books perhaps ;))
    But we'll just have to say: ' approach 'A' works best, on my setup, using dataset X to version Y etc.. and I tested these scenarios, here are the results to which it will be clear why I chose approach 'A'. '. Your results may be different, because I don't know your configuration. "

    This is just good old: 'it depends' (after you ask 'why?')
    And then you will need to dive into your system to "understand why."
    You will need to test and measure.
    trace/tkprof and/or AWR is here to help you with it.

    Sweeping two large table in one of them was sweeping twice for this.

    What is today a large table? The number of records? What is the index? Is there present asymmetric data?
    I'm just pointing to this point, because all that comes to play.
    You should ask a lot of questions in order to get a grip/overview.
    Keep an open mind.

    So, I was looking for as an alternative to avoid twice scan

    Maybe you don't even need to. Perhaps optimizer has done the best it could do for you.
    But please, if you want to be sure: test, trace/tkprof and you will get your answer.
    If you are unsure of the results you can always post and ask here or the DBA (and some authorities of Tuning that hang out there as well this subject ;)) @ the [General Forum database | http://forums.oracle.com/forums/forum.jspa?forumID=61])

    Enclosing: tips are usually a path of last resort. At least: on my PC sloppy, they are always ;)

  • Use two assistants for the acquisition of data at the same time

    Hello

    I want to read multiple data channels of analog inputs on my DAQ hardware. However, when I try to create two separate data acquisition assistants for each entry, it gives an error saying "is reserved for the specified resource. The operation could not be performed as indicated "." Can't use two assistants for the acquisition of data at the same time?

    I have to add different channels in the same assistant DAQ? I tried, but I couldn't separate the data in different graphs.

    How does this work?

    Kind regards

    Allard

    You can't have multiple tasks of the same type (in this case inputs analog) on the same device.  Just so having 1 DAQ Assistant read all your channels and separate your channels for individual transformation.

  • Join query not received from WLC

    Hi all

    I am in the process of autonomous update 1242 (MIC) APs belongs to an external client to make them a part of the existing lwapp based infrastructure.

    I have seen successful negotiations of discovery. Then AP sends the join query, but the WLC debugging does not receive the product.

    1. the capture of wireshark packages indicates that Discovery & jOin process use identical to each phased ports: it will be exclude firewalls.

    2. no duplicate IPs

    3 controllers are not exhausted with APs

    4 DHCP option 43 is set up and could see it in action when I do a debug dhcp

    Another interesting observation is that I couldn't see any CERT on autonomous before conveting to lwapp APs when I have HS crypto pki certificates

    Please refer to the attachment for debugging output.

    Any help is very appreciated.

    see you soon,

    janesha

    You open the FW for UDP 12223 and also you have the ip helper and the ip Protocol before?

  • How many times can I use a variable binding in a query of the VO?

    Is it possible that I can use a variable binding in a query of VO just once?

    I test a query that keeps throwing the Houston-27122 error by pressing the application module tester. I tried to limit the problem to the simplest possible case, and it seems that the error is caused by the fact that I use the same variable bind two or more times.

    When the query looks like this:

    query1.png

    I have run, enter 'x' and it returns me the result.

    When I change to:

    query2.png

    I have run, enter the value

    param.png

    and immediately get the error

    error.png

    The same thing in sqlplus runs without problem:

    sqlplus.png

    My version of JDev is build JDEVADF_11.1.1.9.0_GENERIC_150314.0718.6673

    Please, advise.

    P. S. where can I find documentation queries are supported in your? In particular, I'm interested if I can use WITH the clause. There seems to be some confusion on this matter (see, for example, Oracle SQL WITH clause support - JDeveloper and ADF)

    Thank you.

    It depends on:

    Open your VO in JDev and go the the query page.

    In the lower part, there is a drop down 'link type', it is usually set to "JDBC-positional. In this case, you will need to provide the bind value for each occurrence of the variable binding separately.

    You could change that to "named" (don't remember the exact name). But beware, this will also affect all relatioships master retail to others your. I think that this is not a good idea to change the style of binding to a single VO.

    Good bye

    DPT

Maybe you are looking for