Aggregation SQL

Hello world

I have a problem that I can't solve.

I have this table in the source:

IDPKAXE
180654650
180654654
1806541198
124680654
1246801198
124680853

and I would get before SQL table:

IDAXE-PK
1800
124173

The AXE-PK column is MIN (AXE - PK) > = 0. It cannot be negaive values.

Any suggestion please?

Thank you.

Or simply...

SQL > ed
A written file afiedt.buf

1 with t (ID, PK, AXE) as long as)
2 Select 180, 654, 650 in all the double union
3 select 180, 654, 654 in union double all the
4 Select 180, 654, 1198 in union double all the
5 Select 124, 680, 654 Union double all the
6 select 124, 680, 1198 in union double all the
7. Select 124, 680, 853 double
8         )
9  --
10. select id, min(axe-pk) as axe_pk
11 t
where AX 12-pk > = 0
13 * group by id
SQL > /.

ID AXE_PK
---------- ----------
180 0
124 173

2 selected lines.

Tags: Database

Similar Questions

  • Aggregation SQL logic

    Is it possible to simplify the SQL statement following (STEP 1 and 2 combined)?

    with t as

    (

    Select 1 store_number, 1 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 1 store_number, 1 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 1 store_number, 1 tran_id, 123 as upc,-20 as amount of union double all the

    Select 1 as store_number, 2 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 1 as store_number, 2 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 1 as store_number, 3 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 2 as store_number, 1 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 2 store_number, 2 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 3 as store_number, 1 tran_id, 123 as upc, 10, depending on the amount of double

    )

    -select * from t by 1,2,3;

    -STEP 1

    t1 as

    (

    Select store_number

    tran_id

    upc

    , count (*) as rec_count

    flat as amount

    t

    Store_number group, tran_id, upc

    having plate! = 0

    )

    -select * from t1 by 1,2,3;

    -STEP 2

    Select store_number

    upc

    sum (rec_count) as rec_count

    flat as amount

    from t1

    Store_number group, upc

    order by 1,2,3

    with t as

    (

    Select 1 store_number, 1 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 1 store_number, 1 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 1 store_number, 1 tran_id, 123 as upc,-20 as amount of union double all the

    Select 1 as store_number, 2 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 1 as store_number, 2 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 1 as store_number, 3 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 2 as store_number, 1 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 2 store_number, 2 as tran_id, 123 as upc, 10, depending on the amount of all the double union

    Select 3 as store_number, 1 tran_id, 123 as upc, 10, depending on the amount of double

    )

    SELECT DISTINCT store_number

    upc

    , sum (count (*)) on (store_number partition, upc) as rec_count

    , sum (sum (amount)) on (store_number partition, upc) as the amount

    t

    Store_number group, tran_id, upc

    having plate! = 0

    order by 1,2,3

  • Logic of aggregation in a SQL query

    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production

    I need to write SQL queries to perform the aggregation as mentioned below. Could you please suggest what is the best way to write the query for this task? We have 70 million records in the table of combination and 40 million records in the c_value table.

    Combination table
    CID PLAN ATTR_1 ATTR_2 ATTR_3 ATTR_4
    1001. A C1 P01 S1 #.
    1002. A C2 P01 S1 #.
    1003 F F1 S1 777 P01
    1004 CF C1 P01 S1 777
    1005 CF C2 S1 777 P01
    2001. A S1 P02 C1 #.
    2002. A C2 S1 P02 #.
    F 2003 F1 S1 888 P02
    2004 CF C1 P02 S1 888
    2005 CF C2 S1 888 P02

    C_Amount table
    CID VALUE
    1001 500
    1002 400
    1003 200
    1004 50
    1005 100
    2001 500
    2002 400
    2003 400
    50 2004
    2005 200

    The query result
    ATTR_2 ATTR_3 value
    P01 S1 950
    P02 S1 1050

    Total amount for P01 = sum (a records plan values) + sum (values of records Plan F)-sum (values of plan SEE plan records where F attr_4 = plan CF attr_4)

    = (500 + 400) + (200)-(50 + 100) = 950

    Similarly, the amount Total for P02 = (500 + 400) + (400) - (50 + 200) = 1050

    create table combination (cid number primary key, plan varchar2 (10), attr_1 varchar2 (10), attr_2 varchar2 (10), attr_3 varchar2 (10), attr_4 varchar2 (10));

    create the table c_amount (forced cid number fk_cid combination of references (cid), number of value);
    Insert in the combination values (1001, 'A', 'C1', 'P01', "S1", "#");
    Insert in the combination values (1002, 'A', 'C2', 'P01', "S1", "#");
    Insert in the combination values (1003, 'F', 'F1', 'P01', 'S1', ' 777');
    Insert in the combination values (1004, "CF", "C1", "P01", "S1", ' 777');
    Insert in the combination values (1005, "CF", "C2", "P01", "S1", ' 777');

    insert into c_amount values (1001,500);
    insert into c_amount values (1002,400);
    insert into c_amount values (1003,200);
    insert into c_amount values (1004,50);
    insert into c_amount values (1005,100);

    Insert in the combination values (2001, 'A', 'C1', 'P02', "S1", "#");
    Insert in the combination values (2002, 'A', 'C2', 'P02', "S1", "#");
    Insert in the combination values (2003, 'F', 'F1', 'P02', 'S1', ' 888');
    Insert in the combination values (2004, "CF", "C1", 'P02', 'S1', ' 888');
    insert into values of combination (2005, 'CF', 'C2', 'P02', 'S1', ' 888');

    insert into c_amount values (2001,500);
    insert into c_amount values (2002,400);
    insert into c_amount values (2003,400);
    insert into c_amount values (2004,50);
    insert into c_amount values (2005,200);
    commit;

    Hello

    user13047999 wrote:

    Hi Frank,.

    Thanks for your quick response.

    Combination.attr_4 play a role in this problem?

    Yes. We need to exclude records of plan SEE if attr_4 do correspond with plan F attr_4.

    Please run the instructions below insert also.

    Insert in the combination values (3001, 'A', 'C3', "P01", "S1", "#");

    Insert in the combination values (3002, "CF", "C3", "P01", "S1", ' 111');

    insert into c_amount values (3001,300);

    insert into c_amount values (3002,300);

    commit;

    Now the result of the query should be as below

    ATTR_2 ATTR_3 value

    P01 S1 1250

    P02 S1 1050

    I think I see; If plan = "CF", the coefficient will be-1 if there is a corresponding 'F' row in the table. otherwise, you want to skip the line "CF".  In other words, "we need to exclude records SEE map if attr_4 is NOT mapped to the F attr_4 plan.

    Here's a way to do it:

    WITH got_coef AS

    (

    SELECT attr_2, attr_3, cid

    CASE

    WHEN the intention ('a', 'F')

    THEN 1

    WHEN THERE IS)

    SELECT 1

    COMBINATION cs

    WHERE cs.attr_2 = cm.attr_2

    AND cs.attr_3 = cm.attr_3

    AND cs.attr_4 = cm.attr_4

    AND cs.plan = 'F'

    )

    THEN-1

    Coef END AS

    COMBINATION cm

    WHERE plan IN ('A', 'F', 'CF') - if necessary

    )

    SELECT gc.attr_2, gc.attr_3

    , SUM (ca.value * gc.coef) AS total_value

    OF got_coef gc

    JOIN c_amount ca ON ca.cid = gc.cid

    WHERE gc.coef IS NOT NULL - if necessary

    Gc.attr_2 GROUP, gc.attr_3

    ORDER BY gc.attr_2, gc.attr_3

    ;

    According to what means "correspondent", you may need to change the EXISTS subquery a bit.

    The got_coef of the subquery is not absolutely necessary; you could put the CASE expression in the main query, as I had initially.  (I find it easier to understand in this way, if the argument of the SUM is very complicated, it can be difficult to read and debug.)

  • Any difference between the separate function and aggregation in sql query cost?

    Hello
    I've run many models sql stmts - such as:
    one) using a single table
    (b) using the two tables, using simple joins or outer joins

    but I didn't notice a difference in sql stmts in cost and implementation plan...
    In any case, my colleague insists on only using the aggregate function is less expensive compared to
    separate... (something I've not confirmed, that is why I believe that they are exactly the same...)

    For the situation described above under 1 sql... We could for example use
    select distinct deptno
    from emp
    select count(*), deptno
    from emp
    group by deptno
    select distinct owner, object_type from all_objects
    select count(*), owner, object_type from all_objects
    group by owner, object_type
    Have you ever found no difference between the two...?

    Note: I use Ora DB 10g v2.

    Thank you
    SIM

    Alexandre Gelin says:
    function separate and aggregation are for different uses and can give the same result, but if you use the aggregate function to get the separate records, it will be expensive...

    really? I find them almost identical to 11g. Actually GROUP BY is almost always more fast for me in the old days.

    article about this askTom Re: any difference between the separate function and aggregation in sql query cost?
    This applies mainly to the older oracle versions http://www.oracle.com/technology/products/rdb/pdf/distinct_derivedtables_groupby_sort_tech_article.pdf

  • Aggregation of SQL.

    Hi all

    I have the wide table with multiple records for each S_Id.I separate records for each S_id. The desired output is to apply the rules of each field to get a value by S_id. Each field has its own rules... for example the AADT would be the average value, SINGLE_P should be predominantly etc.
    S_ID     AADT     SINGLE_P     PCT_     AADT_CO     PCT_     K_FAC     DIR_FAC     FUTURE_AADT
    000070     26,215     503     1     5,117     6     13     55     38,130
    000070     26,215     503     1     5,117     6     13     55     38,130
    000070     26,215     503     1     5,117     6     13     55     38,130
    000070     26,215     503     1     5,117     6     13     55     38,130
    000070     25,897     497     1     5,055     6     13     55     38,130
    000070     26,215     503     1     5,117     6     13     55     38,130
    Desired output
    S_ID     AADT     SINGLE_P     PCT_     AADT_CO     PCT_     K_FAC     DIR_FAC     FUTURE_AADT
    000070     26162     503     1     5,117     6     13     55     38,130
    Appreciate any help!

    Thanks in advance
    NU

    Hello

    user32322435 wrote:
    Hi all

    I have the wide table with multiple records for each S_Id.I separate records for each S_id. The desired output is to apply the rules of each field to get a value by S_id.

    Use 'GROUP BY s_id' to get a line of output for each separate s_id.

    Each field has its own rules... for example the AADT would be the average value, SINGLE_P should be predominantly etc.

    Aggregate Oracle functions should do what you want.
    'AVG (AADT)' returns the AADT average for all the lines of he with the same s_id.
    'STATS_MODE (single_p)' returns the single_p value that occurs most often. (That is what you mean by "predominance"?)

    Search for "Aggregate functions" in the manual of the SQL language
    http://docs.Oracle.com/CD/E11882_01/server.112/e26088/functions003.htm#sthref902
    for a complete list of functions and examples of how to use them.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • selection of the results aggregated into a PL/SQL block gives me ORA-00934

    Hello

    I have a simple table of objects on the map that were inclusive. That is to say:
    CREATE TABLE tbl (
      id NUMBER(11,0), -- Id of this record
      parentId NUMBER(11,0), -- Id from some parent table
      bb_sw_lat FLOAT, -- SW bounding box corner - Latitude
      bb_sw_lng FLOAT, -- SW bounding box corner - Longitude
      bb_ne_lat FLOAT, -- NE bounding box corner - Latitude
      bb_ne_lng FLOAT -- NE bounding box corner - Longitude
    );
    
    INSERT INTO tbl VALUES (1, 1, 10, 10, 20, 20);
    INSERT INTO tbl values (2, 1, 5, 5, 35, 35);
    INSERT INTO tbl values (3, 1, -5, -20, 0, 0);
    INSERT INTO tbl VALUES (4, 2, 9, 9, 10, 10);
    INSERT INTO tbl values (5, 2, 1, 1, 1, 1);
    I can query the number of entries for a parent entity and the use of aggregate functions calculate the framework encompassing total for the parent entity:
    SELECT
      count(*),
      NVL(MIN(bb_sw_lat),0),
      NVL(MIN(bb_sw_lng),0),
      NVL(MAX(bb_ne_lat),0),
      NVL(MAX(bb_ne_lng),0)
    FROM tbl
    WHERE parentId=1;
    but the same select cannot be put to the PL/SQL block:
    DECLARE
      cnt NUMBER;
      sw_lat FLOAT; sw_lng FLOAT; ne_lat FLOAT; ne_lng FLOAT;
    BEGIN
      SELECT
        count(*) INTO cnt,
        NVL(MIN(bb_sw_lat),0) INTO sw_lat,    -- ORA-00934: group function is not allowed here
        NVL(MIN(bb_sw_lng),0) INTO sw_lng,
        NVL(MAX(bb_ne_lat),0) INTO ne_lat,
        NVL(MAX(bb_ne_lng),0) INTO ne_lng
      FROM tbl
      WHERE parentId=1;
    END;
    can someone please explain to me why and what to do with it? Examples are executable as they are, it should be fairly easy to reproduce.

    Thank you very much!

    Kuba

    Published by: user3620664 on May 14, 2009 02:14 added formatting

    without testing, just an IN

    DECLARE
      cnt NUMBER;
      sw_lat FLOAT; sw_lng FLOAT; ne_lat FLOAT; ne_lng FLOAT;
    BEGIN
      SELECT
        count(*),
        NVL(MIN(bb_sw_lat),0),
        NVL(MIN(bb_sw_lng),0),
        NVL(MAX(bb_ne_lat),0),
        NVL(MAX(bb_ne_lng),0)
     INTO cnt,
      sw_lat,
      sw_lng,
      ne_lat,
      ne_lng
       FROM tbl
      WHERE parentId=1;
    END;
    

    Published by: Alex Nuijten on May 14, 2009 11:19

  • Problem with SQL aggregation

    I tried several different ways to do it and can't seem to find the right way to do it. We're on 10.2, so not listagg. I have the following information:

    fld_a fld_b fld_c fld_d
    12 10 1 it is
    12-10-2 a test
    14 5 1 second
    14 5 2 test

    I want to have the following result:

    12: 10, it is a test (essentially fld_a, fld_b and fld_d, ordered by fld_c)
    14, 5, second test (the fld_d on a line)

    I'm not listagg, so I tried follows him (and combos of what follows).

    Select fld_a, fld_b, fld_c,
    RTrim (xmlagg (xmlelement (e, fld_d |))) ') .extract ('/ / text()'), ',') 'fld_d '.
    of schemaname.tablename
    Group of fld_a, fld_b, fld_c

    and is not the fld_d of fld_a & fld_b group and ordered by fld_c.

    Any ideas?

    Thank you

    Victoria

    user3804901 wrote:
    I tried several different ways to do it and can't seem to find the right way to do it. We're on 10.2, so not listagg. I have the following information:

    fld_a fld_b fld_c fld_d
    12 10 1 it is
    12-10-2 a test
    14 5 1 second
    14 5 2 test

    I want to have the following result:

    12: 10, it is a test (essentially fld_a, fld_b and fld_d, ordered by fld_c)
    14, 5, second test (the fld_d on a line)

    Your problem is that your output requires no regrouping by FIELD_C - but in your query, you are group by FIELD_C

    Him below will work...

    with t (fld_a,fld_b,fld_c,fld_d) as
    (
    select 12, 10, 1,'this is' from dual union all
    select 12, 10, 2,'a test' from dual union all
    select 14, 5, 1,'second' from dual union all
    select 14, 5, 2,'test' from dual
    )
    select fld_a, fld_b,
            rtrim(
                xmlagg(
                    xmlelement (e, fld_d || ' ') order by fld_c
                      ).extract ('//text()')
                 ) "fld_d"
    from t
    group by fld_a, fld_b
    
    FLD_A FLD_B fld_d
    ----------------------------
       12    10 this is a test
       14     5 second test  
    

    Or sys_connect_by_path as already suggested

    with t (fld_a,fld_b,fld_c,fld_d) as
    (
    select 12, 10, 1,'this is' from dual union all
    select 12, 10, 2,'a test' from dual union all
    select 14, 5, 1,'second' from dual union all
    select 14, 5, 2,'test' from dual
    )
    select rtrim(replace(max(sys_connect_by_path(fld_d,'~')),'~',' ')) fld_d
    from t
    start with fld_c = 1
    connect by prior fld_a=fld_a
     and prior fld_b=fld_b
     and prior fld_c = fld_c-1
    group by fld_a,fld_b ;
    

    Published by: JAC on February 12, 2013 09:50

  • SQL aggregation double

    Hello

    It's a bit more of an Enigma a question.

    SELECT AVG (x) FROM (SELECT deptno, AVG (sal) AS x FROM emp);
    
        AVG(X)
    ----------
    2073.21429
    What is the problem with the above query? Have we not learned in school that the average of the averages is not equal to the average General?

    11.2.0.3 / Solaris Sparc

    Published by: Laurent Schneider on November 4, 2011 13:39

    The CBO playing around...

    Excerpt from a 10053 trace on 11.2.0.2 file:

    SVM:     SVM bypassed: Single grp set fct (aggr) without group by.
    SLP: Removed select list item DEPTNO from query block SEL$2
    
    ...
    
    Final query after transformations:******* UNPARSED QUERY IS *******
    SELECT AVG("from$_subquery$_001"."X") "AVG(X)" FROM  (SELECT AVG("EMP"."SAL") "X" FROM "SCOTT"."EMP" "EMP") "from$_subquery$_001"
    
  • 6210XS SQL Performance Benchmarking

    Our company has recently acquired some new berries for a new ERP system. I am the senior analyst programmer on the project and I'm a beginner-intermediate level on the SAN storage, virtualization and optimization of the performance of SQL. I need to get the speed and at the head of what to expect from this new equipment and best practices to test and manage. Our current ERP is on HP - UX and Informix battery is alien technology in relation to where we are.

    We have a network services division, which was responsible for managing the side home with ESX and EqualLogic 6500 non - ERP. This team is more known in the general management of this equipment, but less time to devote to this new ERP project so I spend to help everyone to get more confidence in the train and educate me about it. Phew. To obtain meat now.

    Setup: dedicated network 10 GB iSCSI with frames enabled. No set MPIO. Dedicated to storage pools for the 6210xs, 6210 (10 K SAS) and 6510 (7200 K). All about the 10 GB.

    I use a tool called MS SQLIO to test the OPS are / s of the 6210XS. I used one of the focus of test by default example of the doc "using SQLIO.

    brief: 6 minutes test, sequential I / O, 2 queries of suspense, of the size of e/s/o requires 256 bytes and a 15 GB test file. The results were:

    H:\SQLIO>SQLIO - kR-s360-fsequential-o2-b256 - LS - Fparam.txt
    SQLIO v1.5.SG
    using meter system for the timings of the latency, 2343750 counts per second
    file settings used: param.txt
    file h:\testfile.dat with 16 (0-15) son using mask 0 x 0 (0)
    16 son of reading for 360 seconds of file h:\testfile.dat
    using 256 KB sequential IOs
    activation of several i/o per thread with 2 exceptional
    the indicated use size: 15000 MB for the file: h:\testfile.dat
    initialization done
    AGGREGATED DATA:
    flow measurements:
    IOs/sec: 133,93
    MBs/s: 33.48
    latency settings:
    Min_Latency (MS): 61
    Avg_Latency (MS): 238
    Max_Latency (MS): 1269

    I made a new test using different settings and had very different results:

    H:\SQLIO>SQLIO - kW - s10 - frandom-o8-b8 - LS - Fparam.txt
    SQLIO v1.5.SG
    using meter system for the timings of the latency, 2343750 counts per second
    file settings used: param.txt
    file h:\testfile.dat with 8 wires (0-7) using mask 0 x 0 (0)
    8 son writing for 10 seconds in the file h:\testfile.dat
    using random 8 KB IOs
    activation of several i/o per thread with 8 exceptional
    the indicated use size: 102400 MB for the file: h:\testfile.dat
    initialization done
    AGGREGATED DATA:
    flow measurements:
    IOs/s: 24122.61
    MBs/s: 188.45
    latency settings:
    Min_Latency (MS): 0
    Avg_Latency (MS): 2
    Max_Latency (MS): 25

    Novice question - this is obviously not a good result, but I need to figure out why my test is configured incorrectly or why the table struggled to perform under these test conditions. Thank you for taking the time to read and respond.

    Usually performance problems are caused by not having is not the SAN (server, switches, table) set up by best practices and in some cases FW drivers and/or obsolete equipment.

    With ESX generally 99% performance problems are solved with:

    Delayed ACK disabled

    People with disabilities large Offload received

    Ensure using Round Robin of VMware (with e / s through changed to 3), or use the EQL MEM (version the most recent is 1.2) Multipathing

    If you use multiple VMDK (or ROW), in the virtual machine, each should have its own virtual SCSI adapter

    Upgrade to the latest build ESX, switch, and server updates

    Take a look at the links listed here first.  See also the Firmware of Array Release notes.

    Best practices for ESX

    en.Community.Dell.com/.../20434601.aspx

    Configuration Guide for EqualLigic

    en.Community.Dell.com/.../2639.EqualLogic-Configuration-Guide.aspx

    Quick Configuration portal (start Grand Place)

    en.Community.Dell.com/.../3615.Rapid-EqualLogic-configuration-Portal-by-SIS.aspx

    Best practices white papers, look for SQL and ESX

    en.Community.Dell.com/.../2632.Storage-Infrastructure-and-solutions-Team-publications.aspx

    Compatibility matrix

    en.Community.Dell.com/.../20438558

    -Joe

  • Tuning for sql join key table no consumer of the heavy use of the query processor

    Obligation comes to tunne prod of the query in

    high use of the query processor

    sql_id: fp79wb32h7a6t

    Module: AHC, P_PatientDQ()

    Cost: 7

    Elapsed time: hung

    Status: Hung, 35,253,460 day at 30 minute intervals

    -Create table

    create table ahc. PATIENTVISITS

    (

    ahcid NUMBER,

    visitId NUMBER,

    visitstatus NVARCHAR2 (100),

    visitdate DATE,

    visitintime DATE,

    visitouttime DATE

    )

    -Create/recreate the index

    create indexes ahc. F1_PATIENTVISIT_AHCID on ahc. PATIENTVISITS (AHCID, VISITID);

    create indexes ahc. VISITDATE_IDX on ahc. PATIENTVISITS (TRUNC (VISITDATE));

    First total number of table

    Select count (1) of

    Pvs AHC.patientvisits

    -Save County 1387485

    create table ahc. PATIENTDEPENDENTVISITS

    (

    ahcid NUMBER (19) not null,

    IDPack NUMBER (10) not null,

    visitId NUMBER (19) not null,

    dependentvisitid NUMBER (19) not null,

    isdiabetic NUMBER (2)

    )

    -Create/recreate the index

    create indexes ahc. K1_PATIENTDEPENDENT_AHCID on ahc. PATIENTDEPENDENTVISITS (AHCID);

    Total number of second table

    Select count (1) of

    AHC.patientdependentvisits POS

    -Save County 774599

    Original request:

    SELECT count (*)

    ACH. PVS PATIENTVISITS

    WHERE PVS. VISITID IN (SELECT POS. DEPENDENTVISITID

    ACH. PATIENTDEPENDENTVISITS POS

    WHERE POS. AHCID = 37

    AND POS. VISITID = 218

    AND POS. ISDIABETIC = 0)

    AND SUPERIOR (PVS. VISITSTATUS) = 'PENDING'

    AND PVS. AHCID = 37

    Count (1)

    -----------

    1

    PL/sql Developer explain plan for the original query

    Owner of description Objects_name cost cardin bytes cpucost cost of e/s

    SELECT STATEMENT, GOAL = ALL_ROWS7141636697
    AGGREGATION OF TRI141
    SEMI OF THE NESTED LOOPS7141636697
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTVISITS4125332954
    INDEX RANGE SCANAHCF1_PATIENTVISIT_AHCID39231643
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTDEPENDENTVISITS3116303753
    INDEX RANGE SCANAHCK1_PATIENTDEPENDENT_AHCID214180932

    After editing the query

    SELECT / * + FIRST_ROWS * / COUNT (1)

    ACH. PVS PATIENTVISITS

    JOIN THE AHC. PATIENTDEPENDENTVISITS POS ON PVS. VISITID = POS. DEPENDENTVISITID

    WHERE PVS. AHCID = POS. AHCID

    AND POS. AHCID = 37

    AND POS. VISITID = 218

    AND POS. ISDIABETIC = 0

    AND SUPERIOR (PVS. VISITSTATUS) = 'PENDING'

    Count (1)

    -----------

    1

    PL/sql Developer explain plan for change request

    Owner of description Objects_name cost cardin bytes cpucost cost of e/s

    SELECT STATEMENT, TARGET = TIP: FIRST_ROWS7141592577
    AGGREGATION OF TRI141
    NESTED LOOPS
    NESTED LOOPS7141592577
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTDEPENDENTVISITS4116366464
    INDEX RANGE SCANAHCK1_PATIENTDEPENDENT_AHCID314243643
    INDEX RANGE SCANAHCF1_PATIENTVISIT_AHCID21152932
    TABLE ACCESS BY INDEX ROWIDAHCPATIENTVISITS3125226113

    here after I changed the query no display cost = 7 io wait = improvement also 7 can someone please help these

    How to adjust or rewrite lots of join not keys to multiple records on table table

    Thank you

    VSM

    you have not answered my question. Are you really calling it 35 million times in 30 minutes?

    If so, why?

  • How to make the sum of the time through SQL?

    Dear friends

    I have a sh_detail table and there are three fields hours1, hours2 hours3. all fields are of type varchar2.

    data are like

    hours1 hours2 total hours3

    02:45 00:18 01:25

    00:38 01:45 00:00

    02:15 02:00 00:15

    1. I want to add on three fields in the total column

    2 and want to make the sum of all areas as select sum (hours1) of sh_detail.

    Please help I will be grateful.

    Kind regards.

    As others have said, use the NUMBER to store times, or the type of data correct INTERVAL, even if the latter cannot be aggregated (using the SUM).

    In the meantime, this will give you the output desired in a few minutes (it is trivial to convert it back in format hh: mm if you wish):

    SQL> with sample_data (id, hours1, hours2, hours3) as (
      2    select 1, '02:45', '00:18', '01:25' from dual union all
      3    select 2, '00:38', '01:45', '00:00' from dual union all
      4    select 3, '02:15', '02:00', '00:15' from dual
      5  )
      6  select id
      7       , sum(h1) h1
      8       , sum(h2) h2
      9       , sum(h3) h3
     10       , sum(h1+h2+h3) as total
     11  from (
     12  select id
     13       , to_number(substr(hours1, 1, 2))*60 + to_number(substr(hours1, 4, 2)) as h1
     14       , to_number(substr(hours2, 1, 2))*60 + to_number(substr(hours2, 4, 2)) as h2
     15       , to_number(substr(hours3, 1, 2))*60 + to_number(substr(hours3, 4, 2)) as h3
     16  from sample_data
     17  )
     18  group by rollup(id) ;
    
            ID         H1         H2         H3      TOTAL
    ---------- ---------- ---------- ---------- ----------
             1        165         18         85        268
             2         38        105          0        143
             3        135        120         15        270
                      338        243        100        681
    
  • Complete surrogate on the target key after aggregation 12 c

    Hi all

    I'm looking to 12 c and much used 11g. I have mocked a table and you want to load into a target table that includes a column, remaps a source column and adds a surrogate key. Remapping looks like this

    Sum (object_id)-> tot_obj_id_by_owner

    ID-> legacy_id

    surrogate_key. Next generation of val.

    Source and target texts to sit in the same pattern of the same db.

    I passed and remapped via the GLOBAL component and columns in the column ID (surrogate key) on the target of the table were mapped using the API call to odiRef.getObjectName.

    So I, in the logical tab table Source (connected to) aggregate (connected to) target Table. IKM is Oracle's SQL.

    I tried to adjust this surrogate key with indicator to execute on the target, but everything I've tried so far has always led to the sequence generated as part of the select statement for aggregate in the taget table insert that Oracle does not like:

    INSERT

    / * + APPEND PARALLEL * /.

    IN DEV. () BIG_TAB_SUM_HEAP

    ID, LEGACY_ID, OWNER, OBJECT_NAME, SUBOBJECT_NAME, TOT_OBJECT_ID_BY_OWNER, DATA_OBJECT_ID, OBJECT_TYPE, CREATED, LAST_DDL_TIME, CR_TIMESTAMP

    )

    SELECT

    DEV. SEQ_GENERIC. NEXTVAL, ID, (BIG_TABLE_EXT OWNER), (BIG_TABLE_EXT. OBJECT_NAME), (BIG_TABLE_EXT. SUBOBJECT_NAME), (SUM (BIG_TABLE_EXT OBJECT_ID)), (BIG_TABLE_EXT. DATA_OBJECT_ID), (BIG_TABLE_EXT. OBJECT_TYPE), (BIG_TABLE_EXT) CREATED, (BIG_TABLE_EXT. LAST_DDL_TIME), (BIG_TABLE_EXT WSJ

    Of

    DEV. BIG_TABLE_EXT BIG_TABLE_EXT

    GROUP BY (BIG_TABLE_EXT,(BIG_TABLE_EXT. PROPRIÉTAIRE) OBJECT_NAME), (BIG_TABLE_EXT.,(BIG_TABLE_EXT. SUBOBJECT_NAME),(BIG_TABLE_EXT. DATA_OBJECT_ID) OBJECT_TYPE), (BIG_TABLE_EXT.,(BIG_TABLE_EXT. CRÉÉ),(BIG_TABLE_EXT. LAST_DDL_TIME),(BIG_TABLE_EXT. STATUT),(BIG_TABLE_EXT. TEMPORAIRE),(BIG_TABLE_EXT. GÉNÉRÉ),(BIG_TABLE_EXT. SECONDAIRE) NAMESPACE),(BIG_TABLE_EXT. EDITION_NAME) (BIG_TABLE_EXT. (BIG_TABLE_EXT.ID) WSJ

    11G setting the Execute on the target for the ID column would have been sufficient to achieve this goal and aggregation have been encapsulated in a subselect / query inline.

    Can anyone help?

    Thank you

    SEV

    SevConsalvation,

    Data sets can be used again in a mapping to force a subselect must be generated. If it doesn't work, you can also try using a reusable mapping.

    Could try to use another IKM? Using a SQL for Oracle KM is quite unusual if source and target are on the same schema.

    Kind regards

    JeromeFr

  • no aggregation of pivot function

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for Linux: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    Hi, thank you very much in advance.

    I want to combine two lines into a single line, group by (area_code, team, office_code, supervisorID) - if the collector ID (IS_DESKCALL = 'Y') and collectorID(IS_DESKCALL='N') in the same line. As it is not an aggregation function, so I can't use function pivot in 11g?

    / * Formatted on 05/11/2014 19:34:09 (v5.139.911.3011 PS5) * /.

    WITH T AS (SELECT '31012' office_code,)

    AREA_code '00003',.

    1 TEAM,

    SUPERVISOR_ID '201204135',

    ' NO IS_DESKCALL.

    '201205000' COLLECTOR_ID

    OF THE DOUBLE

    UNION

    SELECT '31012' office_code,

    AREA_code '00003',.

    1 TEAM,

    SUPERVISOR_ID '201204135',

    'Y' IS_DESKCALL,.

    '201205555' COLLECTOR_ID

    OF THE DOUBLE

    UNION

    SELECT '31012' office_code,

    AREA_code '00003',.

    1 TEAM,

    SUPERVISOR_ID '201204888',

    ' NO IS_DESKCALL.

    '201205000' COLLECTOR_ID

    OF THE DOUBLE

    UNION

    SELECT '31012' office_code,

    AREA_code '00003',.

    1 TEAM,

    SUPERVISOR_ID '201204888',

    'Y' IS_DESKCALL,.

    '201205555' COLLECTOR_ID

    OF THE DOUBLE

    UNION

    SELECT '77777' office_code,

    AREA_code '00003',.

    1 TEAM,

    SUPERVISOR_ID '201204999',

    ' NO IS_DESKCALL.

    '201205023' COLLECTOR_ID

    OF THE DOUBLE

    UNION

    SELECT '77777' office_code,

    AREA_code '00003',.

    1 TEAM,

    SUPERVISOR_ID '201204999',

    'Y' IS_DESKCALL,.

    '201205444' COLLECTOR_ID

    THE DOUBLE)

    SELECT *.

    T

    The result should be:

    office_code area_code team supervisorID collectorID(IS_DESKCALL='Y') collectorID(IS_DESKCALL='N')

    31012 00003 1 201204135 201205555 201205000

    31012 00003 1 201204888 201205555 201205000

    77777 00003 1 201204999 201205444 201205023

    As it is not an aggregation function, so I can't use function pivot in 11g?

    You can use MIN (or MAX):

    select *
    from t
    pivot (
      min(collector_id)
      for is_deskcall in (
        'Y' as collector_id_y
      , 'N' as collector_id_n
      )
    ) ;
    
  • How to add a 'hint' in my query to resolve the error "hash aggregation can be done."

    I have a query Oracle 10 SQL that works very well in the environment of train, but fails live (presumably because of the volume). I get the error. "ORA-00600: internal error code, arguments: [32695] [hash aggregation cannot be done.  Google suggests that I can use a trick to fix this if I'm luckey (i.e. "NO_USE_HASH_AGGREGATION"). How to incorperate a 'hint' in my query?  (where in my query I would put the suspicion and what kind of syntax)?  Thank you!!!

    Optimizer tips shouln can't be used to try to solve the problems, they should be used to analyze issues.

    Before attempting to apply patches of poor to an unknown cause, you'd be btter to identify what is the real problem.

    ORA-00600 errors indicate an internal error and should be reported to Oracle via My Oracle Support (it is also a search tool of ORA-00600 on My Oracle Support, which can help to tell you if it is a known problem that is fixed by a solution of workaround or bug fix/patch etc..)

    Do not use the tips where they should not be used.  Correct the cause of the problem, not the symptom.

  • Aggregation of data

    Hello

    I'm curious to know if this problem can be solved with just of SQL.  I have a table of holds, and I need some sort of aggregation to display all the blocks which lie on a line.  Shims can be placed in the header, in which case they appear on all lines.

    I need the data to display like this. 1 card for each header and the line (shims at the level of the header are displayed on the lines and should not receive its own line, indicated with a null, row_id).

    ID of header row holds holds billing collection shims

    1 1 ' B C L W' "B C" 'L '.

    1         2      'B C L'    'B C'        'L'

    1         3      'C L'      'B'          'L'

    This can be down with only SQL?

    Thank you

    -Johnnie

    CREATE TABLE HOLD_TYPES
    (
      HOLD_ID                NUMBER NOT NULL,
      HOLD_NAME              VARCHAR2(80) NOT NULL,
      HOLD_CODE              VARCHAR2(1),
      HOLD_TYPE              VARCHAR2(20) NOT NULL
    );
    
    
    INSERT INTO HOLD_TYPES
       (HOLD_ID, HOLD_NAME, HOLD_CODE, HOLD_TYPE)
    VALUES
       (1, 'Customized Billing', 'B', 'BILLING' );
    INSERT INTO HOLD_TYPES
       (HOLD_ID, HOLD_NAME, HOLD_CODE, HOLD_TYPE)
    VALUES
       (2, 'Delayed Billing', 'B', 'BILLING' );
    INSERT INTO HOLD_TYPES
       (HOLD_ID, HOLD_NAME, HOLD_CODE, HOLD_TYPE)
    VALUES
       (3, 'Combo Billing', 'C', 'BILLING' );
    INSERT INTO HOLD_TYPES
       (HOLD_ID, HOLD_NAME, HOLD_CODE, HOLD_TYPE)
    VALUES
       (4, 'Staging Block', 'W', 'SHIPPING' );
    INSERT INTO HOLD_TYPES
       (HOLD_ID, HOLD_NAME, HOLD_CODE, HOLD_TYPE)
    VALUES
       (5, 'Waiting Letter of Credit', 'L', 'PICKING' );
    
    
    CREATE TABLE ORDER_HOLDS
    (
      HEADER_ID                        NUMBER        NOT NULL,
      LINE_ID                          NUMBER,
      HOLD_ID                          VARCHAR2(40)  NOT NULL
    );
    
    
    INSERT INTO ORDER_HOLDS
      ( HEADER_ID, LINE_ID, HOLD_ID )
    VALUES( 1, 1, 1 );
    INSERT INTO ORDER_HOLDS
      ( HEADER_ID, LINE_ID, HOLD_ID )
    VALUES( 1, 1, 4 );
    INSERT INTO ORDER_HOLDS
      ( HEADER_ID, LINE_ID, HOLD_ID )
    VALUES( 1, 2, 2 );
    INSERT INTO ORDER_HOLDS
      ( HEADER_ID, LINE_ID, HOLD_ID )
    VALUES( 1, 3, 3 );
    INSERT INTO ORDER_HOLDS
      ( HEADER_ID, LINE_ID, HOLD_ID )
    VALUES( 1, NULL, 5 );
    INSERT INTO ORDER_HOLDS
      ( HEADER_ID, LINE_ID, HOLD_ID )
    VALUES( 1, NULL, 3 );
    
    

    
    
    
    

    Hi, Johnnie,

    Assuming you use Oracle 11.2 or later version, you can use LISTAGG for a list delimited by the aggregate of the codes.

    Applying the shims with a line_id NULL for all real line_ids is more complicated (at least for me).

    Here's one way:

    WITH effective_holds AS

    (

    SELECT header_id

    line_id

    hold_id

    Of order_holds
    WHERE the line_id IS NOT NULL

    UNION

    SELECT l.header_id

    l.line_id

    w.hold_id

    To order_holds l

    JOIN order_holds w l.header_id = w.header_id

    AND l.line_id IS NOT NULL

    AND w.line_id IS NULL

    )

    SELECT eh.header_id, eh.line_id

    , LISTAGG (ht.hold_code, ' ')

    THE Group (ORDER BY ht.hold_code) THAT holds

    , LISTAGG (CASE WHEN ht.hold_type = "BILLING" THEN ht.hold_code END, ' ')

    THE Group (ORDER BY ht.hold_code) AS billing_holds

    , LISTAGG (CASE WHEN ht.hold_type = 'PICKING' THEN ht.hold_code END, ' ')

    THE Group (ORDER BY ht.hold_code) AS picking_holds

    Of effective_holds right

    JOIN hold_types ON ht.hold_id = eh.hold_id ht

    Eh.header_id GROUP, eh.line_id

    ORDER BY eh.header_id, eh.line_id

    ;

    Once again, LISTAGG is new in version 11.2.  If you use Oracle 9.1 or later, you can use instead of LISTAGG SYS_CONNECT_BY_PATH.

    If the same type is applied 2 times or more in the same header_id and line_id, 1 one copy of the code appears in the delimited lists.  If this isn't what you want, then we can change effective_hold; Maybe do a FULL OUTER JOIN instead of a UNION.

    Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

Maybe you are looking for