Can u help me refine this query

create table company
(comp_id number primary key,
comp_name varchar2(50) not null
create table accident
(acc_seq number primary key,
acc_comp_id number not null,
acc_series smallint not null,
acc_id varchar2(10) not null,
acc_type varchar2(50) not null)
-- acc_series is an auto number to tell me total accident this company has so far
insert into company(comp_id,comp_name)
values(10001,'A Corp')
insert into company(comp_id,comp_name)
values(10002,'B Corp')
insert into company(comp_id,comp_name)
values(10003,'C Corp')
insert into accident(acc_seq,acc_comp_id,acc_series,acc_id,acc_type)
values(9001,10001,1,'AC-09-0001','CAR')
insert into accident(acc_seq,acc_comp_id,acc_series,acc_id,acc_type)
values(9002,10002,1,'AC-09-0002','MACHINARY')
insert into accident(acc_seq,acc_comp_id,acc_series,acc_id,acc_type)
values(9003,10001,2,'AC-09-0009','FIELD')
-- problem for this query : I hardcoded number 1,2. In reality, I need a way to find the upper bound first then do the decode ( I think) and adjust the column heading accordingly, can u help ?
select
comp_name,
max(decode(acc_series,1,acc_id)) acc1_id,
max(decode(acc_series,1,acc_type)) acc1_type,
max(decode(acc_series,2,acc_id)) acc2_id,
max(decode(acc_series,2,acc_type)) acc2_type
from company A,accident B
where A.comp_id=B.acc_comp_id
group by comp_name
output
COMP_NAME ACC1_ID ACC1_TYPE ACC2_ID ACC2_TYPE
A Corp      AC-09-0001      CAR      AC-09-0009      FIELD
B Corp      AC-09-0002      MACHINARY
Thanks in advance.
Munshar

It looks like you are after a dynamic pivot.
Check out this post by Frank that goes through an example on how to create a dynamic pivot: {message:id=3227388}

Similar Messages

  • Help to refine this query

    Query function: list out all case no, paid amout that occured for LAST 2 fiscal years for each owner at any given time plus separte sum column for each FY
    Question: I don't like my query with repetition ( what if we need last 10 years). Can you help me refine it ?
    many thanks.
    create table test_case_payment
    case_no number not null,
    owner_no number not null,
    paid_amt number(13,2),
    paid_date date
    create table test_case_quota
    case_no number not null,
    limit number not null
    insert into test_case_payment(case_no,owner_no,paid_amt,paid_date)
    -- data represents FY 2011,2012,2012,2008,2010
    values(1,810,2700,to_date('10/25/2010','MM/DD/YYYY'));
    values(2,820,350,to_date('07/05/2011','MM/DD/YYYY'));
    values(3,810,900,to_date('01/01/2011','MM/DD/YYYY'));
    values(4,840,100,to_date('04/05/2008','MM/DD/YYYY'));
    values(5,850,20,to_date('07/20/2009','MM/DD/YYYY'));
    Insert into test_case_quota(case_no,limit)
    -- paid ceiling
    values(1,2);
    values(2,2);
    values(3,1);
    values(4,1);
    values(5,1);
    -- query starts here
    with FY1 as
    select a.case_no,a.owner_no, a.paid_amt,b.limit,
    NVL(sum(a.paid_amt) over (partition by a.owner_no),0) FY1_TOTAL
    from test_case_payment a,test_case_quota b
    where
    a.case_no=b.case_no
    and a.paid_date between to_date('7/1/'|| ( EXTRACT (YEAR FROM to_date(:FY_BEGIN,'MM/DD/YYYY')) ),'MM/DD/YYYY') and to_date('06/30/' || ( EXTRACT (YEAR FROM to_date(:FY_BEGIN,'MM/DD/YYYY'))+1),'MM/DD/YYYY')
    order by a.owner_no,a.case_no
    FY2 as
    select a.case_no,a.owner_no, a.paid_amt,b.limit,
    NVL(sum(a.paid_amt) over (partition by a.owner_no),0) FY2_TOTAL
    from test_case_payment a,test_case_quota b
    where
    a.case_no=b.case_no
    and a.paid_date between to_date('7/1/'|| ( EXTRACT (YEAR FROM to_date(:FY_BEGIN,'MM/DD/YYYY')) +1),'MM/DD/YYYY') and to_date('06/30/' || ( EXTRACT (YEAR FROM to_date(:FY_BEGIN,'MM/DD/YYYY'))+2),'MM/DD/YYYY')
    order by a.owner_no,a.case_no
    -- union 2 temp tables
    FY_UNION as
    (select case_no,owner_no,paid_amt,limit,
    FY1_TOTAL Y1,null Y2 from FY1
    union
    select case_no,owner_no,paid_amt,limit,
    null Y1,FY2_TOTAL Y2 from FY2)
    -- main query
    select case_no,owner_no,paid_amt,limit,Y1,Y2 from FY_UNION
    order by owner_no
    -- result
    CASE_NO OWNER_NO PAID_AMT     LIMIT      Y1      Y2
    1      810     2700          2     -      3600
    3     810      900           1      -        3600
    5     850      20           1      20      -Edited by: wanwan63 on Oct 30, 2011 11:03 AM
    added format code to display bettter readable output

    Yes, good idea to use a working schema as a proxy. Here's a variation that takes the department as owner and employee as the payment, and returns all payments with amount (=salary) sums for 3 years (I've skipped the FY stuff)...
    WITH     y     AS
         SELECT     LEVEL     AS year_num
         ,     ADD_MONTHS ( TO_DATE ('01011998', 'DDMMYYYY')
                      , 12 * (LEVEL - 1)
                      )              this_year_begin
         ,     ADD_MONTHS ( TO_DATE ('01011998', 'DDMMYYYY')
                      , 12 *  LEVEL
                      )              next_year_begin
         FROM    dual
         CONNECT BY     LEVEL <= 3     -- Can be any positive integer
    ), t AS (
    SELECT     y.year_num, d.department_name, e.salary, e.hire_date,
         Sum (CASE WHEN e.hire_date     >= y.this_year_begin
                       AND e.hire_date     <  y.next_year_begin THEN e.salary END)
         OVER (PARTITION BY d.department_name, y.year_num) sumsal
      FROM employees     e
      JOIN departments     d
        ON d.department_id = e.department_id
      CROSS JOIN y
    WHERE e.hire_date >= TO_DATE ('01011998', 'DDMMYYYY')
    SELECT department_name, hire_date, salary,
         Sum (CASE year_num WHEN 1 THEN sumsal END) y1,
         Sum (CASE year_num WHEN 2 THEN sumsal END) y2,
         Sum (CASE year_num WHEN 3 THEN sumsal END) y3
      FROM t
    GROUP BY department_name, salary, hire_date
    ORDER BY 1, 2;
    DEPT            HIRE_DATE     SALARY         Y1         Y2         Y3
    Finance         07-MAR-98       7800       7800       6900
    Finance         07-DEC-99       6900       7800       6900
    IT              05-FEB-98       4800       4800       4200
    IT              07-FEB-99       4200       4800       4200
    Purchasing      15-NOV-98       2600       2600       2500
    Purchasing      10-AUG-99       2500       2600       2500
    Sales           24-JAN-98       9600      59100      42200      49400
    Sales           23-MAR-98      10000      59100      42200      49400
    Sales           24-MAR-98       8600      59100      42200      49400
    Sales           30-MAR-98       8000      59100      42200      49400
    Sales           23-APR-98       8400      59100      42200      49400
    Sales           03-NOV-98       7000      59100      42200      49400
    Sales           09-DEC-98       7500      59100      42200      49400
    Sales           23-FEB-99       7400      59100      42200      49400
    Sales           19-MAR-99       9500      59100      42200      49400
    Sales           24-MAR-99       7300      59100      42200      49400
    Sales           15-OCT-99      11000      59100      42200      49400
    Sales           23-NOV-99       7000      59100      42200      49400
    Sales           04-JAN-00       6200      59100      42200      49400
    Sales           24-JAN-00       7200      59100      42200      49400
    Sales           29-JAN-00      10500      59100      42200      49400
    Sales           23-FEB-00       6800      59100      42200      49400
    Sales           24-MAR-00       6400      59100      42200      49400
    Sales           21-APR-00       6100      59100      42200      49400
    Sales           21-APR-00       6200      59100      42200      49400
    Shipping        24-JAN-98       3200      37800      26100       9800
    Shipping        12-FEB-98       2700      37800      26100       9800
    Shipping        23-FEB-98       3100      37800      26100       9800
    Shipping        15-MAR-98       2600      37800      26100       9800
    Shipping        06-APR-98       2500      37800      26100       9800
    Shipping        24-APR-98       3100      37800      26100       9800
    Shipping        23-MAY-98       3000      37800      26100       9800
    Shipping        24-JUN-98       3400      37800      26100       9800
    Shipping        01-JUL-98       3200      37800      26100       9800
    Shipping        09-JUL-98       2500      37800      26100       9800
    Shipping        11-JUL-98       2900      37800      26100       9800
    Shipping        26-AUG-98       2900      37800      26100       9800
    Shipping        28-SEP-98       2700      37800      26100       9800
    Shipping        14-JAN-99       2400      37800      26100       9800
    Shipping        07-FEB-99       3000      37800      26100       9800
    Shipping        17-MAR-99       2800      37800      26100       9800
    Shipping        10-APR-99       2100      37800      26100       9800
    Shipping        21-JUN-99       2500      37800      26100       9800
    Shipping        21-JUN-99       2600      37800      26100       9800
    Shipping        16-NOV-99       5800      37800      26100       9800
    Shipping        12-DEC-99       2400      37800      26100       9800
    Shipping        19-DEC-99       2500      37800      26100       9800
    Shipping        13-JAN-00       2600      37800      26100       9800
    Shipping        03-FEB-00       2800      37800      26100       9800
    Shipping        06-FEB-00       2200      37800      26100       9800
    Shipping        08-MAR-00       2200      37800      26100       9800
    51 rows selected.
    Start edit:
    This is actually quite an interesting problem, where neither group by nor analytics alone can solve the problem, so I'll explain how my solution works. I did find a simpler solution though when thinking the explanation through that requires just a small addition to anaytics.
    Grouping won't work because it removes the transaction detail, but the obvious partitioning, department and year, won't work either because then the summation would only be for the transaction's own year. That is why I cross-joined Frank's years view, so that now each transaction is joined to each of the years, and we can then partition by the view year. The first CASE is necessary to sum only the relevant year's transactions for each year row, which we then pivot into columns in the standard way.
    The simpler solution involves partitioning by department only, then using a CASE within the summation to sum the relevant year for each column. [Edited to replace hard-coded dates with input and offsets]. I won't repeat the output, I have tested that it's the same as above.
    VARIABLE     fy_begin     NUMBER
    EXEC  :fy_begin := 1998;
    SELECT     d.department_name dept, e.hire_date, e.salary,
         Sum (CASE WHEN To_Number (To_Char(e.hire_date, 'YYYY')) = :fy_begin THEN e.salary END)
         OVER (PARTITION BY d.department_name) y1,
         Sum (CASE WHEN To_Number (To_Char(e.hire_date, 'YYYY')) = :fy_begin+1 THEN e.salary END)
         OVER (PARTITION BY d.department_name) y2,
         Sum (CASE WHEN To_Number (To_Char(e.hire_date, 'YYYY')) = :fy_begin+2 THEN e.salary END)
         OVER (PARTITION BY d.department_name) y3
      FROM employees     e
      JOIN departments     d
        ON d.department_id = e.department_id
    WHERE e.hire_date >= To_Date ('0101' || To_Char (:fy_begin), 'DDMMYYYY')
    ORDER BY 1, 2;I hope it's clear that the solutions do translate directly to the OP's problem. You can add the FY stuff in either by Frank's view or just replacing the To_Numbered bit by a CASE based on month number being 1-6 or not and the year - it's a bit simpler using CY.
    Edited by: BrendanP on 30-Oct-2011 01:20
    Edited by: BrendanP on 30-Oct-2011 02:01

  • Can u help me on this query

    Hi all,
    I am using 10G. With the following tables and data ( hope this help you to udnerstand my question)
    create table case
    ( case_no number,
    case_name varchar2(100),
    pid number);
    insert into case (case_no,case_name,pid)
    values
    (900,'Driving with loud music',1);
    insert into case (case_no,case_name,pid)
    values
    (910,' Disturb public meeting',2);
    insert into case (case_no,case_name,pid)
    values
    (920,'indecent conduct',3);
    create table person
    (pid number,
    fname varchar2(25),
    lname varchar2(25)
    insert into person
    (pid,fname,lname)
    values
    (1,'JAY','STINKY');
    insert into person
    (pid,fname,lname)
    values
    (2,'Jerry','Jasonx');
    insert into person
    (pid,fname,lname)
    values
    (3,'Wild','Manning');
    create table penalty
    (case_no number,
    pid number,
    fine number,
    court_cost number
    insert into penalty
    (case_no,pid,fine,court_cost)
    values
    (900,1,2000,100);
    insert into penalty
    (case_no,pid,fine,court_cost)
    values
    (910,2,0,100);
    create table community_Service
    (case_no number,
    pid number,
    seq number,
    service varchar2(250)
    insert into community_service
    (case_no,pid,seq,service)
    values
    (900,2,1,'Street Cleaning');
    insert into community_service
    (case_no,pid,seq,service)
    values
    (900,2,2,'Beach Cleaning');
    insert into community_service
    (case_no,pid,seq,service)
    values
    (920,3,1,'Volunteer work');
    insert into community_service
    (case_no,pid,seq,service)
    values
    (920,3,2,'Street Cleaning');I am looking for this answercase_no     case_name          fname     Lanme     fine     court_cost     seq     service
    900     Driving with loud music JAY     STINKY     2000     100          1     street Cleaning
    900     Driving with loud music                           2     Beach Cleaning
    910     Disturb public meeting     Jerry     Jasonx     0     100
    920     Indecent conduct     Wild     Manning                    1     Volunteer Work
    920     Indecent conduct                              2     Street CleaningThe following is my unsuccessful codes( it has repetition on name and penalty when no entries involved)
    select
    A.case_no, A.case_name
    ,B.fname,B.lname
    ,C.fine,c.court_cost
    ,D.seq,D.service
    from
    case A,
    Person B,
    Penalty C,
    community_Service D
    where
    A.pid=B.pid(+)
    and A.case_no=C.case_no(+)
    and A.pid = B.pid(+)
    and A.case_no=D.case_no(+)
    order by case_no,case_name,fname,lname,seq
    Thanx
    Zeng

    Hi, Zeng,
    zeng wrote:
    Frank Kulash wrote:
    Hi, Zeng,
    So, you only want to display vertain columns (fname, lname, fine and court_cost) on the 1st row for a case; on the 2nd (and later) rows, you want to display NULL in those columns. Is that right?
    Frank,
    Always good to learn from your comments.
    Nope. I am looking for a report that will display all persons involved in each case plus penalty and community services. If no penalty or community service then show the person's name ( revised desired output was in my reply to Nikolay)Are you saying that you do want the fname, lname and fine repeated on all lines after all? I assume you mean that, in addition to hiding those items, there's another issue, concenrning multuiple persons associated with the same case.
    How do we know which fine and which service are related to which person? Is it the pid column in the penalty and community_service tables? If so, then we need to include pid in the join conditions. To display the fname and lname on the first row for every distinct case/person combination (instead of just for every cae), then we need to add pid to the analytic PARTITION BY clause, also.
    WITH       got_r_num   AS
         SELECT       c.case_no
         ,        c.case_name
         ,       pr.fname
         ,       pr.lname
         ,       pn.fine
         ,       pn.court_cost
         ,       cs.seq
         ,       cs.service
         ,       ROW_NUMBER () OVER ( PARTITION BY  c.case_no
                                      ,          c.pid     -- ***** NEW *****
                                      ORDER BY          cs.seq
                             )           AS r_num
         FROM        cases               c
         ,       person          pr
         ,       penalty           pn
         ,       community_service     cs
         WHERE       c.pid          = pr.pid (+)
         AND       c.case_no     = pn.case_no (+)
         AND       c.pid          = pn.pid (+)               -- *****  NEW  *****
         AND       c.pid          = pr.pid (+)
         AND       c.case_no     = cs.case_no (+)
         AND       c.pid          = cs.pid (+)               -- *****  NEW  *****
    SELECT       case_no
    ,        case_name
    ,       CASE WHEN r_num = 1 THEN fname      END     AS fname
    ,       CASE WHEN r_num = 1 THEN lname      END     AS lname
    ,       CASE WHEN r_num = 1 THEN fine           END     AS fine
    ,       CASE WHEN r_num = 1 THEN court_cost END     AS court_cost
    ,       seq
    ,       service
    FROM        got_r_num
    ORDER BY  case_no
    ,       fname
    ,       lname
    ,       seq
    ;The output I get from your sample data is:
    CASE                                               COURT
    _NO CASE_NAME                 FNAME LNAME    FINE _COST  SEQ SERVICE
    900 Driving with loud music   JAY   STINKY   2000   100
    910  Disturb public meeting   Jerry Jasonx      0   100
    920 indecent conduct          Merry Lamb
    920 indecent conduct          Wild  Manning                1 Volunteer work
    920 indecent conduct                                       2 Street CleaningNote that there is no community_service associated with JAY STINKY, pid=1. In your sample data:
    insert into community_service
    (case_no,pid,seq,service)
    values
    (900,2,1,'Street Cleaning');
    insert into community_service
    (case_no,pid,seq,service)
    values
    (900,2,2,'Beach Cleaning');all the community_service for case_no=900 was assigned to pid=2, Jerry Jasonx, who is not related to case_no=900. I assume there's a mistake in the sample data. You can add foreign key constraints to the tables to prevent mistakes like that.

  • How do tune sql query? Can somebody help me in this? Atleast prescribe book

    how do tune sql query? Can somebody help me in this? Atleast prescribe a reference book.
    I am not able understand How to analyze tkproof output.

    Check out asktom.oracle.com
    Lot's of threads on interpreting tkprof output - no simple easy solution here.
    You need to understand what is happening and THINK. Then you can be a good engineer.
    As for good books...
    Tom Kyte's books are really, really good.
    http://www.amazon.com/Effective-Oracle-Design-Osborne-ORACLE/dp/0072230657/ref=sr_1_3?ie=UTF8&s=books&qid=1266783471&sr=8-3
    http://www.amazon.com/Expert-Oracle-Database-Architecture-Programming/dp/1590595300/ref=sr_1_1?ie=UTF8&s=books&qid=1266783471&sr=8-1
    Good luck!

  • Need help in refining the query

    Hello Experts,
    Need your help in refining the query further more.
    table structure 
    Mskey  Col A Col B
    1   empno [20141127-20151128]1234
    1   empno [20151201-99991231]232544
    1   salutation [20141127-99991231]Mrs
    1   salutation [20151127-99991231]Mr
    2   empno [20141127-20151128]1234
    2   empno [20151201-99991231]232544
    2   salutation [20141127-99991231]Mrs
    2   salutation [20151127-99991231]Mr
    My requirement is to find the list of overlapping records based on the dates
    user details may be varying from time to time as new data would be pushed through HR systems to identity store via an interface.
    The job is getting failed whenever there is any overlapping with dates. So we proactively decided to schedule a job in this regards which runs weekly and would let us know for which and all the users there is overlapping dates are there, so that we can send the list to HR team for pushing new data.
    Overlapping Issue Example:
    The users employee id for an year it is 1234 and later he moved to another department and his employee id got changed and it became 2345 remaining all details are same. So the HR systems send the data for this user as empno - [20141127-20151128]1234 and empno - [20151201-99991231]232544
    it means from 20141127 to 20151128 his employee no is 1234 and from 20151201 to 99991231 his employee would be 2345.
    This is a correct case and the tool would accept this data.
    the below cases are invald
    Case 1: 1 salutation [20141127-99991231]Mrs 1 salutation [20151127-99991231]Mr
    Case 2: 2 salutation [20141127-99991231]Mrs 2 salutation [20141127-99991231]Mr
    So we wanted to find these overlapping records from tables.
    My Query:
    I am able to successfully write query for the case 2 type but unable to write for case1.
    select id,colA
    count(left(ColB,CHARINDEX(']',ColB))) as 'Count'
    from tblA with (nolock)
    where id in (Select distinct id from tblb with (nolock))
    group by id, cola,left(ColB,CHARINDEX(']',ColB))
    having count(left(ColB,CHARINDEX(']',ColB)))>1

    Finally got the required answer with the below query
    WITH Cte AS
    SELECT ID,ColA,ColB,ROW_NUMBER() OVER(ORDER BY (SELECT 1)) AS RN,
    CAST(SUBSTRING(ColB,2,CHARINDEX('-',ColB)-2) AS DATE) AS StartDT,
    CAST(SUBSTRING(ColB,CHARINDEX('-',ColB)+1,8) AS DATE)  AS EndDT  FROM TblA
    SELECT c1.ID, c1.ColA,c1.ColB
    FROM Cte c1 JOIN Cte c2
    ON c1.RN != c2.RN
    AND c1.ID=c2.ID
    AND c1.ColA=c2.ColA
    AND (c1.StartDT BETWEEN c2.StartDT AND c2.EndDT OR c2.StartDT BETWEEN c1.StartDT AND c1.EndDT )

  • HELP TO TUNE THIS QUERY

    Hi,
    I'm using below query in procedure.It's taking more more time can some one help to tune this query or advice to rewrite the query.
    Databse :10.1
    SELECT   'Reading Comprehension' TEST_NAME,T.TEST_END_DATE TEST_SESSION_DATE,
            C.POOL_VERSION_ID, I.CREATED_ON POOL_CREATED_DT,
            C.ITEM_ID, C.ITEM_RESPONSE_ID, S.STUDENT_ID_PK, C.RESPONSE_KEY, C.IS_CORRECT RESPONSE_IS_CORRECT,
            T.SCORE SCALE_SCORE, C.RESPONSE_DURATION, P.ITEM_KEY,
            T.TEST_SESSION_DETAIL_ID, SYSDATE CREATED_ON
           -- BULK COLLECT INTO TV_PSYCHO_DET
            FROM
            CAT_ITEM_PARAMETER P, CAT_ITEM_USER_RESPONSE C, TEST_SESSION_DETAIL T,
            TEST_SESSION S, ITEM_POOL_VERSION I, TEST_DETAIL D
            ,INSTITUTION E
            WHERE  TRUNC(T.TEST_END_DATE) BETWEEN TO_DATE('01-11-09','dd-mm-yy') AND TO_DATE('30-11-09','dd-mm-yy')
            AND D.TEST_NAME =  'Reading Comprehension'
            AND T.TEST_SESSION_STATUS_ID = 3
            AND I.POOL_AVAILABILITY='Y'
            AND P.PRETEST=0 AND C.RESTART_FLAG=0
            AND T.TEST_DETAIL_ID = D.TEST_DETAIL_ID
            AND S.TEST_SESSION_ID = T.TEST_SESSION_ID
            AND C.TEST_SESSION_DETAIL_ID = T.TEST_SESSION_DETAIL_ID
            AND S.INSTITUTION_ID=E.INSTITUTION_ID
            AND SUBSTR(E.INSTITUTION_ID_DISPLAY,8,3) <> '000'
            AND I.ITEM_ID = C.ITEM_ID
            AND P.ITEM_ID = I.ITEM_ID;expln plan
    Plan hash value: 3712814491                                                                                                      
    | Id  | Operation                                 | Name                        | Rows  | Bytes | Cost (%CPU)| Time     | Pstart|
    Pstop |                                                                                                                          
    |   0 | SELECT STATEMENT                          |                             | 50857 |  7151K| 93382   (1)| 00:18:41 |       |
          |                                                                                                                          
    |*  1 |  FILTER                                   |                             |       |       |            |          |       |
          |                                                                                                                          
    |*  2 |   HASH JOIN                               |                             | 50857 |  7151K| 93382   (1)| 00:18:41 |       |
          |                                                                                                                          
    |   3 |    PARTITION HASH ALL                     |                             |  2312 | 23120 |    25   (0)| 00:00:01 |     1 |
        5 |                                                                                                                          
    |*  4 |     TABLE ACCESS FULL                     | CAT_ITEM_PARAMETER          |  2312 | 23120 |    25   (0)| 00:00:01 |     1 |
        5 |                                                                                                                          
    |*  5 |    HASH JOIN                              |                             | 94938 |    12M| 93356   (1)| 00:18:41 |       |
          |                                                                                                                          
    |*  6 |     TABLE ACCESS FULL                     | ITEM_POOL_VERSION           |  9036 |   132K|    30   (0)| 00:00:01 |       |
          |                                                                                                                          
    |*  7 |     TABLE ACCESS BY GLOBAL INDEX ROWID    | CAT_ITEM_USER_RESPONSE      |     9 |   279 |    18   (0)| 00:00:01 | ROWID |
    ROWID |                                                                                                                          
    |   8 |      NESTED LOOPS                         |                             | 45349 |  5270K| 93325   (1)| 00:18:40 |       |
          |                                                                                                                          
    |*  9 |       HASH JOIN                           |                             |  4923 |   423K| 11377   (1)| 00:02:17 |       |
          |                                                                                                                          
    |* 10 |        INDEX FAST FULL SCAN               | INSTI_ID_NAME_COUN_DISP_IDX |  8165 |   111K|    18   (0)| 00:00:01 |       |
          |                                                                                                                          
    |* 11 |        HASH JOIN                          |                             |  4923 |   355K| 11359   (1)| 00:02:17 |       |
          |                                                                                                                          
    |* 12 |         TABLE ACCESS BY GLOBAL INDEX ROWID| TEST_SESSION_DETAIL         |  4107 |   148K|  6804   (1)| 00:01:22 | ROWID |
    ROWID |                                                                                                                          
    |  13 |          NESTED LOOPS                     |                             |  4923 |   278K|  6806   (1)| 00:01:22 |       |
          |                                                                                                                          
    |* 14 |           INDEX RANGE SCAN                | TEST_DETAIL_AK_1            |     1 |    21 |     2   (0)| 00:00:01 |       |
          |                                                                                                                          
    |* 15 |           INDEX RANGE SCAN                | TEST_SESSION_DETAIL_FK2_I   | 39737 |       |   102   (0)| 00:00:02 |       |
          |                                                                                                                          
    |  16 |         PARTITION HASH ALL                |                             |  1672K|    25M|  4546   (1)| 00:00:55 |     1 |
        5 |                                                                                                                          
    |  17 |          TABLE ACCESS FULL                | TEST_SESSION                |  1672K|    25M|  4546   (1)| 00:00:55 |     1 |
        5 |                                                                                                                          
    |* 18 |       INDEX RANGE SCAN                    | CAT_ITEM_USER_RESP_IDX1     |    18 |       |     3   (0)| 00:00:01 |       |
          |                                                                                                                          
    Predicate Information (identified by operation id):                                                                              
       1 - filter(TO_DATE('01-11-09','dd-mm-yy')<=TO_DATE('30-11-09','dd-mm-yy'))                                                    
       2 - access("P"."ITEM_ID"="I"."ITEM_ID")                                                                                       
       4 - filter("P"."PRETEST"=0)                                                                                                   
       5 - access("I"."ITEM_ID"="C"."ITEM_ID")                                                                                       
       6 - filter("I"."POOL_AVAILABILITY"='Y')                                                                                       
       7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0)                                                                                   
       9 - access("S"."INSTITUTION_ID"="E"."INSTITUTION_ID")                                                                         
      10 - filter(SUBSTR("E"."INSTITUTION_ID_DISPLAY",8,3)<>'000')                                                                   
      11 - access("S"."TEST_SESSION_ID"="T"."TEST_SESSION_ID")                                                                       
      12 - filter(TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))>=TO_DATE('01-11-09','dd-mm-yy') AND "T"."TEST_SESSION_STATUS_ID"=3   
                  AND TRUNC(INTERNAL_FUNCTION("T"."TEST_END_DATE"))<=TO_DATE('30-11-09','dd-mm-yy'))                                 
      14 - access("D"."TEST_NAME"='Reading Comprehension')                                                                           
      15 - access("T"."TEST_DETAIL_ID"="D"."TEST_DETAIL_ID")                                                                         
      18 - access("C"."TEST_SESSION_DETAIL_ID"="T"."TEST_SESSION_DETAIL_ID")                                                         
    43 rows selected.Edited by: user575115 on Dec 18, 2009 12:31 AM

    When you see something like ...
       7 - filter(TO_NUMBER("C"."RESTART_FLAG")=0)                                                                                    It means that Oracle had to do a conversion for you since you aren't using the proper data type in your query.
    That would mean IF there is an index on that column, it won't be useable...

  • Help to Simplify this query

    i am using
    Oracle8i Enterprise Edition Release 8.1.7.4.0 - Production
    With the Partitioning option
    JServer Release 8.1.7.4.0 - Production
    Please help to simplify this query. I also want to make this as a procedure.
    select
    RH.resort as RH_RESORT,
    RH.rate_code as RH_RATE_CODE,
    RD.rate_detail_id as RD_RATE_DETAIL_ID,
    RD.rate1 as RD_RATE1,
    RD.rate2 as RD_RATE2,
    RD.rate3 as RD_RATE3,
    RD.rate4 as RD_RATE4,
    RD.rate5 as RD_RATE5,
    RRC.room_category as RM_CAT,
    initcap(RRMCAT.long_description) as RM_DESC,
    RH.DAY1,
    RH.DAY2,
    RH.DAY3,
    RH.DAY4,
    RH.DAY5,
    RH.DAY6,
    RH.DAY7,
    RH.WEEKEND1,
    RH.WEEKEND2,
    RH.WEEKEND3,
    RH.WEEKEND4,
    RH.WEEKEND5,
    RH.WEEKEND6,
    RH.WEEKEND7
    from pms_rate_header RH,
    pms_rate_detail RD,
    pms_rate_room_cat RRC,
    resort_room_category RRMCAT
    where RH.inactive_date is NULL
    and RH.RESORT='FABGOI'
    and RH.RATE_CODE ='CRRRACK'
    and ('15-Jan-2007' >= RH.BEGIN_DATE
    and '16-Jan-2007' <= RH.END_DATE)
    and RD.rate_header_id=RH.rate_header_id
    and RD.inactive_date is NULL
    and ('15-Jan-2007' >= RD.BEGIN_DATE
    and '16-Jan-2007' <= RD.END_DATE)
    and RRC.rate_detail_id=RD.rate_detail_id
    and RRC.resort=RH.resort
    and RRMCAT.resort=RH.resort
    and RRMCAT.room_category=RRC.room_category
    and RRC.inactive_date is NULL
    and RRMCAT.inactive_date IS NULL
    regards
    lee1212

    where RH.inactive_date is NULL
    and RH.RESORT='FABGOI'
    and RH.RATE_CODE ='CRRRACK'
    and ('15-Jan-2007' >= RH.BEGIN_DATE
    and '16-Jan-2007' <= RH.END_DATE)
    and RD.rate_header_id=RH.rate_header_id
    and RD.inactive_date is NULL
    and ('15-Jan-2007' >= RD.BEGIN_DATE
    and '16-Jan-2007' <= RD.END_DATE)
    and RRC.rate_detail_id=RD.rate_detail_id
    and RRC.resort=RH.resort
    and RRMCAT.resort=RH.resort
    and RRMCAT.room_category=RRC.room_category
    and RRC.inactive_date is NULL
    and RRMCAT.inactive_date IS NULL
    in the above part i am finding repeated joins and lot of 'and's
    i want to know any line can be eliminated or the the query can be rewritten in a simple way without affecting it's accuracy?
    regards
    Lee1212

  • Plz help me design this query

    Hi,
    Can you’ll please help me with this query.
    Here is a little bit of background:
    One title can have multiple items associated with it.
    Table: TITLE has the master list of titles. TITLE_ID is the primary key.
    Table: ITEM has the master list of all items. ITEM_ID is the primary. This table also has the TITLE_ID which stores title for this item.
    Table: ITEM_STATUS has fields ITEM_ID and STATUS_ID. This field contains statuses for items. But not all items contained in the table ITEM are in this table.
    I want to find TITLE_ID’s whose all items (all ITEM_ID in table ITEM having same value for TITLE_ID) have a particular status (for example STATUS_ID = 2) in table ITEM_STATUS.
    Let’s say TITLE_ID = 1 has 5 items in table ITEM_ID and only 4 items out of it in table ITEM_STATUS with STATUS_ID = 2, then this TITLE_ID should not come. OR
    Let’s say TITLE_ID = 1 has 5 items in table ITEM_ID and all these 5 items are in table ITEM_STATUS but only 1 has STATUS_ID = 2, then this TITLE_ID should also not come
    In the above case only if all 5 items are contained in table ITEM_STATUS have STATUS_ID = 2 then this TITLE_ID should be reported by the query.
    What should be the query like for this one, I am fairly new to SQL so plz guide me.
    Thank you,
    Raja

    I haven't tested the query below. Try it and let me know for any issues:
    SELECT     DISTINCT t.title_id
         FROM     title t,
                        item i,
                        item_status its
    WHERE     t.title_id = i.title_id
         AND     i.item_id = its.item_id
         AND     NOT EXISTS     (
                                                           SELECT 1
                                                                FROM item_status its1
                                                           WHERE its1.item_id = i.item_id
                                                                AND status_id <> 'YOUR_ITEM_STATUS'
                                                      )

  • Could you please help me make this query less complicated

    could you please help me make this query less complicated
    select t1.R_OBJECT_ID
    from dm_relation_sp a, ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID
    union all
    select t3.R_OBJECT_ID
    from ddt_resolution_sp t3
    where t3.R_OBJECT_ID in (select t2.child_id
    from dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    union all
    select t4.R_OBJECT_ID
    from ddt_resolution_sp t4
    where t4.R_OBJECT_ID in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    union all
    select t5.R_OBJECT_ID
    from ddt_resolution_sp t5
    where t5.R_OBJECT_ID in
    (select t4.child_id
    from dm_relation_sp t4
    where t4.parent_id in(
    select t3.child_id from dm_relation_sp t3
    where t3.parent_id in (
    select t2.child_id
    from asud_fsk.dm_relation_sp t2
    where t2.parent_id in (select a.child_id
    from asud_fsk.dm_relation_sp a, asud_fsk.ddt_resolution_sp t1
    where a.parent_id = '0900000283560456' -----------ID
    and a.child_id = t1.R_OBJECT_ID))
    and t3.relation_name = 'RESOLUTION_RELATION')
    and t4.relation_name = 'RESOLUTION_RELATION')
    Edited by: user13025450 on 29.04.2010 16:23

    Hi,
    Welcome to the forum! You'll find that there are many qualified people (such as Tubby) willing to help you. Will you do what you can to help them? In order to simplify the query you posted,someone will first have to understand what it does, what the tables that it uses are like, and what tools you have to work with (that is, what version of Oracle, and any other software you are using). To actually test their ideas, people will need versions of your tables.
    Many people, if they spent enough time, might be able to figure out roughly what you are doing, make some tables themselves and test a solution. You can help with all of that. I assume you already know what the appliction is, and what this particular query is supposed to do: you don't have to figure out any of that, you just have to say it. You know what all your tables are, what the datatypes of all the columns are, and what kinds of data are in the tables: you don't have to guess at any of that.
    Describe what you're doing. Think about it: how do we know that
    SELECT  NULL
    FROM    dual;doesn't do what you want?
    Post CREATE TABLE and INSERT statements for a little sample data.
    Post the results that this query is supposed to produce from those results. (Is it producing the right output now? Then it should be easy to post the correct results.)
    Describe, as well as you can, how the present query is doing it.
    Format your existing code, so it's easy to see what the different branches of the UNION are, and what the main clauses are in each one.
    When posting formatted text (code or results) type these 6 characters
    \(all small letters, inside curly brackets) before and after each formatted section, to keep this site from compressing the spaces.
    Say what versions of Oracle (e.g. 10.2.0.3.0) and any other relevant software you are using.
    I know it's a lot of work, but it really helps. You can do it as well (probably better) than anyone else, and if you're unwilling to do it, why should anyone else be willing?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • I urgently need a contact email for the sales team can anybody help me with this

    I urgently need a contact email for the sales team regarding an outstanding query, can anybody help me with this please? Thanks in advance.

    Hello 
    Welcome to the EE Community! I'm afraid there isn't an e-mail you can contact the EE Mobile Sales team on, but here's how you can get in touch with them:
    If you're on Twitter, you can tweet them @EE, however If you'd prefer to talk to someone, you can dial:
    150 from your EE mobile phone
    If you're ringing from another phone, it's 01707 315000
    For handy text codes & more, check out this page: http://ee.co.uk/help/get-in-touch Cheers,
    Titanium
    Was my post helpful? Please take 2 seconds to hit the 'Kudos' button below

  • My ipod touch 1st gen has gone into recovery and wont restore because of a error 1 or something like that can someone help me quick this ipod is my little cousins and i dont want her mum to find out what happend

    my ipod touch 1st gen has gone into recovery and wont restore because of a error 1 or something like that can someone help me quick this ipod is my little cousins and i dont want her mum to find out what happend

    I have not seen a solution for error (1)
    make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • Can you help me with this ( vlan,accesslist,management )

    here's the scenario I have two vlan 10 & 20
    I have 2 switch and 1 router
    the target of this setup is that vlan 10 can ping or reach vlan 20 but vlan 20 cannot be reach or ping vlan 10 it is that possible
    Here's the setup
    In SW0
    vlan 10
    name Management
    interface FastEthernet0/1
    switchport access vlan 10
    switchport mode access
    interface FastEthernet0/2
    switchport trunk allowed vlan 10
    switchport mode trunk
    In SW1
    interface FastEthernet0/1
    switchport trunk allowed vlan 20
    switchport mode trunk
    interface FastEthernet0/2
    switchport access vlan 20
    switchport mode access
    interface FastEthernet0/3
    switchport access vlan 20
    switchport mode access
    In Router
    interface FastEthernet0/0.10
    encapsulation dot1Q 10
    ip address 192.168.10.1 255.255.255.0
    ip access-group 1 out
    interface FastEthernet0/0.20
    no ip address
    interface FastEthernet0/1
    no ip address
    duplex auto
    speed auto
    interface FastEthernet0/1.20
    encapsulation dot1Q 20
    ip address 192.168.20.1 255.255.255.0
    ip access-group 1 out
    interface Vlan1
    no ip address
    shutdown
    ip classless
    access-list 1 deny 192.168.20.0 0.0.0.255
    access-list 1 permit 192.168.10.0 0.0.0.255
    access-list 1 deny host 192.168.20.11
    access-list 1 permit host 192.168.10.11
    access-list 1 deny any
    access-list 1 permit any
    Im new so i dont know if my setup is correct ...
    can any1 help me about this,,,
    thanks.

    Hi,
    let's suppose PC0(Vlan 10) wants to communicate with PC1(Vlan 20):
    -traffic enters f0/0.10 with src 10.11 and dst 20.11 and it is forwarded out f0/1.20 where there is an egress ACL
    -this is a standard ACL so it matches on source only and there is a hit for second entry permit 192.168.10.0 0.0.0.255
    -now PC1 replies and traffic enters f0/1.20 and is forwarded out f0/0.10 where there is egress ACL
    -there is a hit on first entry  deny 192.168.20.0 0.0.0.255( packet src is 20.11 and dst 10.11)
    So end result is that Vlan 10 cannot reach Vlan 20.
    I don't think this is what you wanted
    Now of course traffic sourced from any PC in Vlan 20 destined to PC0 is filtered as you wanted because  it is filtered on f0/0.10 outbound as above.
    ACLs are stateless and communication in TCP/IP is bidirectional so the best way to achieve what you want to do if you want to filter more than Pings would be to use CBAC or ZBF or reflexive ACLs
    Regards
    Alain
    Don't forget to rate helpful posts.

  • Some of my photos in iphoto turn blank (white) when I tried to edit the size like zoon in and out.Can someone help me on this?

    Some of my photos in Iphoto turn blank (white) when I tried to edit the size like zoon in and out.Can someone help me on this?

    As a Test:
    Hold down the option (or alt) key and launch iPhoto. From the resulting menu select 'Create Library'
    Import a few pics into this new, blank library. Is the Problem repeated there?

  • HT204146 Good morning.  I just purchased Imatch but cannot download my music from an iphone 5 to IMatch in Icloud.  Can you help me with this?

    Good morning.  I just purchased Imatch but cannot download my music from an iphone 5 to IMatch in Icloud.  Can you help me with this?

    Hi
    Has iTunes completed its scan of your iTunes library on your computer Subscribing to iTunes from an iOS device.
    Jim

  • "It is formatted incorrectly, or is not a format that iBooks can open". Can anyone help me with this message of a book that I purchased on iBooks, read, highlighted in the book and now I can't open it anymore. Please help!!!

    "It is formatted incorrectly, or is not a format that iBooks can open". Can anyone help me with this message of a book that I purchased on iBooks, read, highlighted in the book and now I can't open it anymore. Please help!!!

    Mine does the same thing occasionally, is your phone jailbroken? Sometimes it will work if you delete the book and reinstall it or put your phone into airplane mode then turn it back off.

Maybe you are looking for

  • Proper user and group rights

    Dear readers and admins My question is about the "correct" setting of the user and group rights, so the following is possible. It relates to Server 10.3 and to 10.4. Requirements: Group 1 = "Regular user" Group 2 = "Administration, Accounting" User 1

  • How to change the value of data supplier host parameter in PI7.1

    Hi Frnds, I want to change the data supplier host parameter to Hostname,when i checked in SLD Administration its pointing to local host,so i wnat to change it. What is the procedure to change the value to host?? i am working on PI7.1 EHP1. THANKS, Ra

  • Problem with printing dynamically created pages

    Hello, I have created a form in Designer 7.1 with one page. When clicking the Print button the script generates additional pages with the instance manager (addInstance) and then I want to print the generated pages. However, when using 'xfa.host.numPa

  • Updates on macbook air

    I am having trouble performing current updates.  The systems will not update and will not shutdown.  Any solutions?

  • Can't re-install Premier trial after deleting it...

    Hi, last week I decided to trial Premier - I downloaded the Application Manager and hit "TRY" downloaded Premier. Then, my mac screen  went all weird (long story) so I trashed everything (thinking that the download had somehow caused issues). Since t