Help with query Condition

--Sample create/insert :
create table xxdummy(
id integer,
name varchar2(40),
description varchar2(100)
insert into xxdummy values (1,'L', 'Simple L press');
insert into xxdummy values (2,'XL', 'XL with no film');
insert into xxdummy values (2,'web', 'XL with no film');
insert into xxdummy values (3,'XL', 'XL with Film');
insert into xxdummy values (3,'Film', 'XL with Film');
insert into xxdummy values (3,'print', 'XL with Film');
insert into xxdummy values (4,'S', 'servo with film');
insert into xxdummy values (4,'Film','servo with film' );
insert into xxdummy values (5,'S','only servo' );
insert into xxdummy values (6,'L', 'Simple L press');
insert into xxdummy values (7,'XL', 'XL with no film');
insert into xxdummy values (8,'XL', 'XL with Film');
insert into xxdummy values (8,'Film', 'XL with Film');
insert into xxdummy values (8,'guide', 'XL with Film');
--drop table xxdummy;
select * from xxdummy;
select id, description, decode(name, 'L', 'L Only', 'XL', 'Got XLs here', 'dont know' ) type
from xxdummy
where name in ('L','XL' )
In above query for column type, I want to display 'L Only', 'XL With Film', 'XL Without Film'
How can I do this ?
Thanks

I should have explained more, but my mind is so fried making up sample replica of the data as its scattered over so many tables in the original query taht I couldnt put it properly:
another try :
column Description is just for my reference , So please ignore that for now.
I have to form a condition only using colums name and id.
select * from xxdummy :
id=2 and 7 , has name=XL but doesnt have 'Film' so I want to mark this row as 'XL with no film'
id=3 and 8 , has name=XL and also has name = Film, So label for this should be - XL With Film
id=4 , has name=S and also Film, --All the ids that have name=S, no matter if it has film with same Id should be excluded.
id=5, exclude it
id=1 and 6 have name = L , Lable them 'L Only' .
So I should basically have 6 rows returned in my sample data :
select id, description, name, decode(name, 'L', 'L Only', 'XL', 'Got XLs here' ,'dont know') type
from xxdummy
where name in ('L','XL')
how do I distinguish within id, that has name=XL : which one has film and which one doesnt
did it sound better ?
Edited by: OAF-dev on Nov 17, 2009 4:10 PM

Similar Messages

  • I need help with the conditional build tag option RoboHelp 10

    I need help with the conditional build tag option. I want to apply CBT to content in a topic. I looked at the Help topics and believed that I applied the feature correctly. Howver, it is not working as desired. In the 2nd sentence below I want the text highlighted in blue to only appear for the printed output and the text printed in purple to only appear for the .htm /online output. Please help.
    There are common tasks used to manage the folders in the Navigator and the folders
    in the BBS Folders Viewer Grid. For more information on these common tasks see Help
    and Support in Success Enterprise. click the links below.

    Hi there
    Using tagging is a two part process.
    Part One
    You create and apply the tags to the information you wish to control.
    Part Two
    You create a Build Expression that is used when you generate your output. The Build Expression typically reads something like: NOT Tag1 (or whatever your tag name is)
    Then when you generate and use the Build Expression, the information tagged is not included in the build.
    Cheers... Rick

  • Help with query calculations (recursive)

    Hi All,
    I want some help with a query using a base rate and the result use in the next calculation year.
    Here an example:
    create table rate_type(
    rate_type_id    number,
    rate_desc       nvarchar2(50),
    rate_base_year  number
    insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (1, 'Desc1', 4.6590);
    insert into rate_type(rate_type_id, rate_desc, rate_base_year) values (2, 'Desc2', 4.6590);
    create table rates (
    rate_type_id number
    rate_year    number,
    rate_value   number
    insert into rates(rate_type_id, rate_year, rate_value) values (1, 2012, 1.2);
    insert into rates(rate_type_id, rate_year, rate_value) values (1, 2013, 1.3);
    insert into rates(rate_type_id, rate_year, rate_value) values (1, 2014, 1.4);
    insert into rates(rate_type_id, rate_year, rate_value) values (2, 2012, 1.2);
    insert into rates(rate_type_id, rate_year, rate_value) values (2, 2013, 1.3);
    insert into rates(rate_type_id, rate_year, rate_value) values (2, 2014, 1.4);The calculation for the first year should be the base rate of the rate type. The next year should use the result of the previous year and so on.
    The result of my sample data is:
    2012 = 4.659 + 1.2 + 4.659 * (1.2 * 0.01) = 5.9149
    2013 = 5.9149 + 1.3 + 5.9149 * (1.3 * 0.01) = 7.1859
    2014 = 7.1859 + 1.4 + 7.1859 * (1.4 * 0.01) = 8.4721Query result:
    NAME 2012 2013 2014
    Desc1 5.9149 7.1859 8.4721
    Desc2 XXXX XXX XXXX
    How can I do this in one select statement? Any ideas?
    Thanks!

    Assuming you are on 11.2:
    with t as (
               select  a.rate_type_id,
                       rate_desc,
                       rate_year,
                       rate_base_year,
                       rate_value,
                       count(*) over(partition by a.rate_type_id) cnt,
                       row_number() over(partition by a.rate_type_id order by rate_year) rn
                 from  rate_type a,
                       rates b
                 where a.rate_type_id = b.rate_type_id
        r(
          rate_type_id,
          rate_desc,
          rate_year,
          rate_base_year,
          rate_value,
          cnt,
          rn,
          result
         ) as (
                select  rate_type_id,
                        rate_desc,
                        rate_year,
                        rate_base_year,
                        rate_value,
                        cnt,
                        rn,
                        rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
                  from  t
                  where rn = 1
               union all
                select  t.rate_type_id,
                        t.rate_desc,
                        t.rate_year,
                        t.rate_base_year,
                        t.rate_value,
                        t.cnt,
                        t.rn,
                        r.result + t.rate_value + r.result * t.rate_value * 0.01 result
                  from  r,
                        t
                  where t.rate_type_id = r.rate_type_id
                    and t.rn = r.rn + 1
    select  *
      from  (
             select  rate_desc name,
                     rate_year,
                     result
               from  r
               where rn <= cnt
      pivot (sum(result) for rate_year in (2012,2013,2014))
      order by name
    NAME             2012       2013       2014
    Desc1        5.914908  7.2918018 8.79388703
    Desc2        5.914908  7.2918018 8.79388703
    SQL> Obviously pivoting assumes you know rate_year values upfront. If not, then without pivoting:
    with t as (
               select  a.rate_type_id,
                       rate_desc,
                       rate_year,
                       rate_base_year,
                       rate_value,
                       count(*) over(partition by a.rate_type_id) cnt,
                       row_number() over(partition by a.rate_type_id order by rate_year) rn
                 from  rate_type a,
                       rates b
                 where a.rate_type_id = b.rate_type_id
        r(
          rate_type_id,
          rate_desc,
          rate_year,
          rate_base_year,
          rate_value,
          cnt,
          rn,
          result
         ) as (
                select  rate_type_id,
                        rate_desc,
                        rate_year,
                        rate_base_year,
                        rate_value,
                        cnt,
                        rn,
                        rate_base_year + rate_value + rate_base_year * rate_value * 0.01 result
                  from  t
                  where rn = 1
               union all
                select  t.rate_type_id,
                        t.rate_desc,
                        t.rate_year,
                        t.rate_base_year,
                        t.rate_value,
                        t.cnt,
                        t.rn,
                        r.result + t.rate_value + r.result * t.rate_value * 0.01 result
                  from  r,
                        t
                  where t.rate_type_id = r.rate_type_id
                    and t.rn = r.rn + 1
    select  rate_desc name,
            rate_year,
            result
      from  r
      where rn <= cnt
      order by name,
               rate_year
    NAME        RATE_YEAR     RESULT
    Desc1            2012   5.914908
    Desc1            2013  7.2918018
    Desc1            2014 8.79388703
    Desc2            2012   5.914908
    Desc2            2013  7.2918018
    Desc2            2014 8.79388703
    6 rows selected.
    SQL> SY.

  • File Upload Problem - help with a condition

    Dear all,
    I have built a form that includes a file upload. Everything works great until I don't include a file for upload(!) It wont allow me to "not" upload a file, it throws an error at me. My database allows this field to be blank. Do I have to wite some sort of condition that allows the file field to be blank, if so, could anyone help with it?
    Many thanks

    Hello,
    Can any one at Adobe help with this please as I still cannot understand why I am forced to upload a file with the file upload control. What happens if I dont want to add a file with my insert form??? I get errors if I do not include a file:
    Developer Details:
    Folder error. Security Error. Folder 'C:\Inetpub\Www_root\absbiodiesel.co.uk\' is out of base folder 'C:\Inetpub\Www_root\absbiodiesel.co.uk\NewsArticles\'. (FOLDER_DEL_SECURITY_ERROR)
    tNG Execution Trace - VIEW
    tNG_insert.executeTransaction
    STARTER.Trigger_Default_Starter
    tNG_insert.doTransaction
    BEFORE.Trigger_Default_FormValidation
    tNG_insert.prepareSQL
    tNG_insert.executeTransaction - execute sql
    tNG_insert.postExecuteSql
    AFTER.Trigger_FileUpload*
    ERROR.Trigger_Default_Insert_RollBack
    tNG_insert.getRecordset
    tNG_insert.getFakeRsArr
    tNG_insert.getLocalRecordset
    tNG_insert.getFakeRecordset
    tNG_insert.getFakeRecordset

  • Help with query rewrite and materialized views

    Hello everybody,
    I'm currently learning how to use Oracle (10G Enterprise) and in particular, Materialized Views.
    I seem to have a problem making the optimizer use a materialized view. I have already set the OPTIMIZER_MODE, QUERY_REWRITE_ENABLED and QUERY_REWRITE_INTEGRITY as needed.
    I need to create a materialized view for the following query:
    Q1:
    SELECT PS_SUPPKEY, PS_PARTKEY, PS_SUPPCOST
    FROM PARTSUPPLIER E, PART WHERE PS_PARTKEY=P_PARTKEY and (lower(P_COMMENT) LIKE ''_o_a\%'' or lower(P_COMMENT) LIKE ''_o_u\%'')
    and PS_SUPPCOST =
    (SELECT min( PS_SUPPCOST)
    FROM PARTSUPPLIER I
    WHERE E.PS_PARTKEY=I.PS_PARTKEY)'
    I created it using the following code:
    CREATE MATERIALIZED VIEW mv_q1
    ENABLE QUERY REWRITE
    AS SELECT PS_SUPPKEY, PS_PARTKEY, PS_SUPPCOST
    FROM PARTSUPPLIER E JOIN PART ON (PS_PARTKEY=P_PARTKEY)
    WHERE lower(P_COMMENT) LIKE '_o_a%' or lower(P_COMMENT) LIKE '_o_u%'
    and PS_SUPPCOST=
    (SELECT min( PS_SUPPCOST)
    FROM PARTSUPPLIER I
    WHERE E.PS_PARTKEY=I.PS_PARTKEY);
    I have created the statistics using:
    execute dbms_stats.gather_table_stats('frandres',' mv_q1');
    execute dbms_stats.gather_table_stats('frandres','PARTSUPPLIER');
    execute dbms_stats.gather_table_stats('frandres','PART');
    Both partsupplier and part are tables and not views.
    When executing Q1, the plan does not use the materialized view. Furthermore, when using explain rewrite:
    DECLARE
    qrytxt VARCHAR2(3000) := 'SELECT PS_SUPPKEY, PS_PARTKEY, PS_SUPPCOST
    FROM PARTSUPPLIER E, PART WHERE PS_PARTKEY=P_PARTKEY and (lower(P_COMMENT) LIKE ''_o_a\%'' or lower(P_COMMENT) LIKE ''_o_u\%'')
    and PS_SUPPCOST =
    (SELECT min( PS_SUPPCOST)
    FROM PARTSUPPLIER I
    WHERE E.PS_PARTKEY=I.PS_PARTKEY)';
    BEGIN
    dbms_mview.EXPLAIN_REWRITE
    (qrytxt,'MV_Q1','MV_Q1');
    END;
    I get the following message:
    MESSAGE
    QSM-01150: query did not rewrite
    QSM-01263: query rewrite not possible when query references a dictionary table o
    r view
    QSM-01219: no suitable materialized view found to rewrite this query
    What I can't understand is why it says I am referencing the dictionary or a view?
    If I remove the (lower(P_COMMENT) LIKE ''_o_a\%'' or lower(P_COMMENT) LIKE ''_o_u\%'') condition to the query (using the same materialized view), I get the following message from EXPLAIN_REWRITE:
    MESSAGE
    QSM-01150: query did not rewrite
    QSM-01219: no suitable materialized view found to rewrite this query
    Which is reasonable.
    I don't know if the like condition is messing up my materialized view. Can anyone please help?
    Thanks a lot in advance.
    Edited by: user12072111 on Oct 29, 2009 9:43 PM

    Bingo!
    The 10.2.0.3 patch set is supposed to fix this ( [List of bugs fixed (MVs)|http://www.dbatools.net/doc/bug10203.html#MVIEW] )
    In particular:
    5052568      Query rewrite does not work for SQL with LIKE clause.
    Thank you very much for your message!
    The downside is that I'm only using Oracle for educational purposes and consequently have no Metalink id, so I can't install the patch. Thanks a lot though!

  • APD with Query (conditions ) !

    Hi,
    1. I am trying to run a Query (with Top 15 Condition) using the APD and dump the results  into a file on   Application server.
    The query takes 5 min when run on BEx web and retrieves 35,000 records with just 3 columns.
    But when i run APD its short dumps after 2 hours
    Is it because i am using Conditions in the query  or because  of APD cant handle 30 million of records from the cube which i have ?
    I appreciate if you any one can  throw some light on this
    Thanks

    I did remember some note that said that conditions were a big no in terms of using the same in an APD...
    Maybe this will help
    Note 751577 - APD-FAQ: Data source query
    Edited by: Arun Varadarajan on Mar 19, 2009 10:28 PM

  • Help with filter condition

    Hi
    I need to have a condition in the which gives available hours , considering the tester whose decommision date is not greater than the day_date.
    I have 4 tables :
    3 dimension tables and 1 fact table
    dim_date : has all possible dates in all formats
    dim_tester : has the all the tester values , and its inception ( when the tester was bought) and decommision(when the tester was decommsioned or removed)
    dim_time : which has hour seg prime values , and the available hours for a day
    Fct_tester_utilization : this table has the keys to link all the dimension tables and the logged hours (used hours) details.
    i need to calculate available hours based on the inception date and decommision date.
    A tester is considered to be online if its between inception and decommsion date, and available hours has to be calculated for all the testers online, if the tester is decommisioned then it has the date value of when its decommsioned if not it has the far value like 12/31/9999.
    Here is the ddl and some sample data
    CREATE TABLE EDW_DIM.DIM_DATE
      DATE_KEY NUMBER(*, 0)
    , DAY_DATE DATE
    , SUN_WEEK_START_DATE DATE )
    Sample Data:
    DATE_KEY DAY_DATE   SUN_WEEK_START_DATE
    3260     05-DEC-10     05-DEC-10
    3261     06-DEC-10     05-DEC-10
    3262     07-DEC-10     05-DEC-10
    3263     08-DEC-10     05-DEC-10
    3264     09-DEC-10     05-DEC-10
    3265     10-DEC-10     05-DEC-10
    3266     11-DEC-10     05-DEC-10
    3267     12-DEC-10     12-DEC-10
    3268     13-DEC-10     12-DEC-10
    3269     14-DEC-10     12-DEC-10
    3270     15-DEC-10     12-DEC-10
    3271     16-DEC-10     12-DEC-10
    3272     17-DEC-10     12-DEC-10
    3273     18-DEC-10     12-DEC-10
    3274     19-DEC-10     19-DEC-10
    3275     20-DEC-10     19-DEC-10
    3276     21-DEC-10     19-DEC-10
    3277     22-DEC-10     19-DEC-10
    3278     23-DEC-10     19-DEC-10
    3279     24-DEC-10     19-DEC-10
    3280     25-DEC-10     19-DEC-10
    3281     26-DEC-10     26-DEC-10
    3282     27-DEC-10     26-DEC-10
    3283     28-DEC-10     26-DEC-10
    DIM_TESTER:
    CREATE TABLE EDW_DIM.DIM_TESTER
      TESTER_KEY NUMBER(10, 0) NOT NULL
    , TESTER_NAME VARCHAR2(25 BYTE)
    , TESTER_CATEGORY VARCHAR2(25 BYTE)
    , TESTER_INCEPTION_DATE DATE
    , TESTER_DECOMMISSION_DATE DATE
    Sample data:
    TESTER_KEY TESTER_NAME TESTER_CATEGORY  TESTER_INCEPTION_DATE TESTER_DECOMMISSION_DATE
    401     RFR6155-2     Bench     02-NOV-06     31-DEC-99
    402     RFR6250-2     Bench     02-NOV-06     25-SEP-09
    403     RFR6250-3     Bench     02-NOV-06     31-DEC-99
    404     RFR6250-7     Bench     02-NOV-06     31-DEC-99
    405     RFR6275-2     Bench     02-NOV-06     27-MAY-08
    406     RFR6275-3     Bench     02-NOV-06     31-DEC-99
    407     SMOKY             Bench     02-NOV-06     31-DEC-99
    408     SUGAR             Bench     02-NOV-06     31-DEC-99
    409     ZIF-02             Bench     02-NOV-06     31-DEC-99
    410     ZIF-03             Bench     02-NOV-06     25-SEP-09
    411     ZIF-04             Bench     02-NOV-06     25-SEP-09
    412     ZIF-18             Bench     02-NOV-06     31-DEC-99
    413     ACDC             ATE     05-NOV-03     09-DEC-06
    414     AEROSMITH     ATE     05-FEB-05     15-OCT-09
    416     BEATLES             ATE     10-APR-06     02-OCT-07
    417     BLAINE          SIMULATOR     14-MAY-03     31-DEC-09
    418     BURNS          SIMULATOR     02-SEP-03     31-DEC-09
    419     CAPOTE             ATE     16-JUN-05     31-DEC-99
    420     CHICO             ATE     03-JUN-03     31-DEC-99
    421     CLASH             ATE     01-APR-04     09-NOV-10
    422     DAPHNE             ATE     29-DEC-04     31-DEC-99
    424     EXACTA             ATE     24-MAR-03     31-DEC-99
    425     FOGHAT             ATE     16-JUN-05     31-DEC-99
    427     GRATEFULDEAD     ATE     05-MAR-03     05-NOV-07
    428     GRENACHE     ATE     06-JAN-06     31-DEC-99
    431     IDITAROD     ATE     24-MAR-03     31-DEC-99
    432     IRONMAIDEN     ATE     20-JUL-03     30-JAN-07
    434     LEDZEPPELIN     ATE     01-FEB-05     07-NOV-10
    531     RFALAB-037     Bench     01-SEP-07     31-DEC-99
    532     UFLEX1             ATE     18-SEP-07     14-OCT-08
    DIM_TIME
    CREATE TABLE EDW_DIM.DIM_TIME
      TIME_KEY NUMBER
    , HOUR_SEG_PRIME VARCHAR2(50 BYTE)
    Sample Data:
    TIME_KEY HOUR_SEG_PRIME
    1     AM-OS:12 AM - 7 AM
    61     AM-OS:12 AM - 7 AM
    121     AM-OS:12 AM - 7 AM
    181     AM-OS:12 AM - 7 AM
    241     AM-OS:12 AM - 7 AM
    301     AM-OS:12 AM - 7 AM
    361     AM-OS:12 AM - 7 AM
    421     AM-Eng:7 AM - 9 AM
    481     AM-Eng:7 AM - 9 AM
    541     Prime Time:9 AM - 7 PM
    601     Prime Time:9 AM - 7 PM
    661     Prime Time:9 AM - 7 PM
    721     Prime Time:9 AM - 7 PM
    781     Prime Time:9 AM - 7 PM
    841     Prime Time:9 AM - 7 PM
    901     Prime Time:9 AM - 7 PM
    961     Prime Time:9 AM - 7 PM
    1021     Prime Time:9 AM - 7 PM
    1081     Prime Time:9 AM - 7 PM
    1141     PM-Eng:7 PM - 10 PM
    1201     PM-Eng:7 PM - 10 PM
    1261     PM-Eng:7 PM - 10 PM
    1321     PM-OS:10 PM - 12 AM
    1381     PM-OS:10 PM - 12 AM
    FCT_TESTER_UTILIZATION:
    CREATE TABLE EDW_FACT.FCT_TESTER_UTILIZATION
      TESTER_KEY NUMBER(10, 0)
    , DIM_DATE_KEY NUMBER(10, 0)
    , DIM_TIME_KEY NUMBER(10, 0)
    , LOGGED_TIME NUMBER(10, 0)
    Sample Data:
    DIM_DATE_KEY     DIM_TIME_KEY     TESTER_KEY     LOGGED_TIME
    3260     1     345     60
    3260     1     347     60
    3261     1     707     60
    3261     1     708     60
    3261     1     709     60
    3261     1     710     60
    3261     1     711     60
    3261     1     713     60
    3261     1     715     60
    3261     1     722     60
    3261     1     723     60
    3261     1     724     60
    3261     1     726     60
    3261     61     345     60
    3261     61     355     60I have calculated available hours :
    Here is my query :
    SQL SELECT
    B.HOUR_SEG_PRIME,
    t.tester_name,
    TRUNC(c.DAY_DATE + 1,'IW')-1 AS Week,
    c.DAY_DATE,
    t.tester_inception_date,
    t.tester_decommission_date,
                   CASE
                        WHEN B.HOUR_SEG_PRIME = 'AM-OS:12 AM - 7 AM' THEN 0.292
                        WHEN B.HOUR_SEG_PRIME = 'AM-Eng:7 AM - 9 AM' THEN 0.083
                        WHEN B.HOUR_SEG_PRIME = 'Prime Time:9 AM - 7 PM' THEN 0.417
                        WHEN B.HOUR_SEG_PRIME = 'PM-Eng:7 PM - 10 PM' THEN 0.125
                        WHEN B.HOUR_SEG_PRIME = 'PM-OS:10 PM - 12 AM' THEN 0.083
                   END
              )* 24 AS "Available_Hours"
    FROM dim_time B join fct_tester_utilization f
    on  f.dim_time_key = B.time_key
    join dim_date c
    on f.dim_date_key = c.date_key
    join dim_tester t
    on t.tester_key = f.tester_key I have not written a where condition in the above query , could any one please assist me in writing query considering the above mentioned conditions for inception and decommision dates?
    Output with the above query:
    WEEK TESTER_NAME DAY_DATE INCEPTION_DATE DECOMMISION_DATEAVAILABLE_HOURS
    12/5/2010     BROWN     12/6/2010     11/2/2006     12/31/9999     10.01
    12/5/2010     CHICO     12/11/2010     6/3/2003     12/31/9999     3.00
    12/5/2010     MEGATRACE     12/8/2010     8/20/2009     8/27/2010     10.01
    12/5/2010     MEGATRACE     12/9/2010     8/20/2009     8/27/2010     10.01
    12/5/2010     MEGATRACE     12/10/2010     8/20/2009     8/27/2010     10.01
    12/5/2010     MERLOT     12/5/2010     3/24/2003     12/31/9999     7.01
    12/5/2010     MEZCAL     12/5/2010     6/2/2006     12/31/9999     7.01
    12/5/2010     OUZO     12/11/2010     4/23/2008     12/31/9999     1.99
    12/5/2010     RFALAB-080     12/9/2010     1/17/2009     12/31/9999     10.01
    12/5/2010     RFR6275-2     12/8/2010     11/2/2006     5/27/2008     10.01
    12/12/2010     MEGATRACE     12/13/2010     8/20/2009     8/27/2010     10.01
    12/12/2010     MEGATRACE     12/16/2010     8/20/2009     8/27/2010     10.01
    12/12/2010     MEZCAL     12/18/2010     6/2/2006     12/31/9999     7.01
    12/19/2010     MARCO     12/25/2010     3/24/2003     12/31/9999     7.01
    12/19/2010     MEGATRACE     12/21/2010     8/20/2009     8/27/2010     10.01
    12/19/2010     MEGATRACE     12/22/2010     8/20/2009     8/27/2010     10.01
    12/19/2010     MERLOT     12/22/2010     3/24/2003     12/31/9999     10.01
    12/26/2010     MALBEC     12/27/2010     4/14/2006     12/31/9999     10.01
    12/26/2010     MARCO     1/1/2011     3/24/2003     12/31/9999     7.01
    12/26/2010     MEGATRACE     12/28/2010     8/20/2009     8/27/2010     10.01In the above output the tester MEGATRACE has already been decommsioned on 8/27/2010 but still there is a day_date , i should not calculate available hours for the testers which have already been decommisoned.
    Expected Output :
    WEEK     TESTER_NAME     DAY_DATE     TESTER_INCEPTION_DATE     TESTER_DECOMMISION_DATE     AVAILABLE_HOURS
    12/5/2010     BROWN     12/6/2010     11/2/2006     12/31/9999     10.01
    12/5/2010     CHICO     12/11/2010     6/3/2003     12/31/9999     3.00
    12/5/2010     MERLOT     12/5/2010     3/24/2003     12/31/9999     7.01
    12/5/2010     MEZCAL     12/5/2010     6/2/2006     12/31/9999     7.01
    12/5/2010     OUZO     12/11/2010     4/23/2008     12/31/9999     1.99
    12/5/2010   RFALAB-080    12/9/2010      1/17/2009     12/31/9999     10.01
    12/12/2010     MEZCAL     12/18/2010     6/2/2006     12/31/9999     7.01
    12/19/2010     MARCO     12/25/2010     3/24/2003     12/31/9999     7.01
    12/19/2010     MERLOT     12/22/2010     3/24/2003     12/31/9999     10.01
    12/26/2010     MALBEC     12/27/2010     4/14/2006     12/31/9999     10.01
    12/26/2010     MARCO     1/1/2011     3/24/2003     12/31/9999     7.01
    12/26/2010    MEGATRACE     8/26/2010      8/20/2009    8/27/2010     10.01The last day_date for Megatrace should not be greater than the decommsionned date.Please Help
    Edited by: user13502884 on Feb 10, 2011 11:11 AM
    Edited by: user13502884 on Feb 10, 2011 1:23 PM
    Edited by: user13502884 on Feb 10, 2011 1:24 PM

    Peter Gjelstrup wrote:
    user13502884 wrote:
    Please let me know if my question is not clear ....My personal opinion: Too much work to be done, turning you sample data into something usuable. Had you posted it as insert statements, several people might already be working at your issue.
    Right now, I haven't even read it to the end..
    Sorry to say
    PeterThere is so much of data for a week , so i was unable to figure out how much sample data i can post , please look into the last set of sample data obtained by my query , which gives an idea of what i am looking into...
    is there a way where i can send some excel files?

  • Help with query output

    Hello, I have the following query that I'm running in Oracle SQL Developer 1.2.1
    WITH group_by_4_column_results AS
    (SELECT m_atschunk.employee AS employee,
    SUM(CASE
    WHEN
    M_ATSCHUNK.rolloffDaysCount = '108545043' AND m_atschunk.infractiondate BETWEEN SYSDATE - 365 AND SYSDATE THEN 1 ELSE 0 END) as rolloffs,
    M_ATSCHUNK.INFRACTIONDATE + 365 as infractionDate
    FROM M_ATSCHUNK
    group by employee, infractionDate, rolloffDaysCount
    SELECT g4.*,
    SUM (rolloffs) OVER (PARTITION BY employee) AS total_rolloffs
    FROM group_by_4_column_results g4
    It will output the key elements of what I need. But where it sums up the 'total_rolloffs', I need to add that number back into the infractiondate column. Any help would be greatly appreciated.
    CREATE TABLE M_ATSCHUNK
    (EMPLOYEE varchar(50),
    ROLLOFFDAYSCOUNT varchar(3),
    INFRACTIONDATE date)
    INSERT INTO M_ATSCHUNK (EMPLOYEE, ROLLINGOFFDAYSCOUNT, INFRACTIONDATE)
    VALUES ('PHIL','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('PHIL','YES', (to_date('2010/01/02 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('PHIL','YES', (to_date('2010/01/03 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('PHIL','YES', (to_date('2010/01/04 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('PHIL','YES', (to_date('2010/01/05 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('PHIL','NO', (to_date('2010/02/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('PHIL','NO', (to_date('2010/03/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('NIKI','YES', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss'))),
    VALUES ('NIKI','NO', (to_date('2010/01/01 08:00:00', 'yyyy/mm/dd hh24:mi:ss')))

    Phil3061 wrote:
    I need to add that number back into the infractiondate column.Well, in general you need to use UPDATE or better MERGE. Howebver, your data sample does not show any rollofs:
    SQL> SELECT * FROM M_ATSCHUNK;
    EMPLOYEE                                           ROL INFRACTIO
    PHIL                                               YES 01-JAN-10
    PHIL                                               YES 02-JAN-10
    PHIL                                               YES 03-JAN-10
    PHIL                                               YES 04-JAN-10
    PHIL                                               YES 05-JAN-10
    PHIL                                               NO  01-FEB-10
    PHIL                                               NO  01-MAR-10
    NIKI                                               YES 01-JAN-10
    NIKI                                               YES 01-JAN-10
    NIKI                                               YES 01-JAN-10
    NIKI                                               NO  01-JAN-10
    EMPLOYEE                                           ROL INFRACTIO
    NIKI                                               NO  01-JAN-10
    NIKI                                               NO  01-JAN-10
    NIKI                                               NO  01-JAN-10
    14 rows selected.
    SQL> WITH group_by_4_column_results AS
      2  (SELECT m_atschunk.employee AS employee,
      3  SUM(CASE
      4  WHEN
      5  M_ATSCHUNK.rolloffDaysCount = '108545043' AND m_atschunk.infractiondate BETWEEN SYSDATE - 365 AND SYSDATE THEN 1 ELSE 0 END) as
    rolloffs,
      6  M_ATSCHUNK.INFRACTIONDATE + 365 as infractionDate
      7  FROM M_ATSCHUNK
      8  group by employee, infractionDate, rolloffDaysCount
      9  )
    10  SELECT g4.*,
    11  SUM (rolloffs) OVER (PARTITION BY employee) AS total_rolloffs
    12  FROM group_by_4_column_results g4
    13  /
    EMPLOYEE                                             ROLLOFFS INFRACTIO TOTAL_ROLLOFFS
    NIKI                                                        0 01-JAN-11              0
    NIKI                                                        0 01-JAN-11              0
    PHIL                                                        0 01-JAN-11              0
    PHIL                                                        0 02-JAN-11              0
    PHIL                                                        0 03-JAN-11              0
    PHIL                                                        0 04-JAN-11              0
    PHIL                                                        0 05-JAN-11              0
    PHIL                                                        0 01-FEB-11              0
    PHIL                                                        0 01-MAR-11              0
    9 rows selected.
    SQL> So adjust data sample and based on it tell us what are the expected results.
    SY.

  • Need help with query that can look data back please help.

    hi guys i have a table like such
    CREATE TABLE "FGL"
        "FGL_GRNT_CODE" VARCHAR2(60),
        "FGL_FUND_CODE" VARCHAR2(60),
        "FGL_ACCT_CODE" VARCHAR2(60),
        "FGL_ORGN_CODE" VARCHAR2(60),
        "FGL_PROG_CODE" VARCHAR2(60),
        "FGL_GRNT_YEAR" VARCHAR2(60),
        "FGL_PERIOD"    VARCHAR2(60),
        "FGL_BUDGET"    VARCHAR2(60)
      )and i have a data like such
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7470','4730','02','10','2','200');I bascially need to get the total of the budget column. however its not as simple as it sound(well atleast not for me.) the totals carry over to the new period. youll noticed the you have a period column. basically what im saying is that
    fgl_grant_year 10 period 1 = for account 7600 its $100 and $100 for period 2 you see 100 dollars again this is not to be added this is the carried over balance. which remains $100.
    so im trying to write a query that basically does the following.
    im given a period for the sake of this example lets say period 1 i get nothing else. I have to find the greates grant year grab the amount for period 14(which is the total from the previous year) and add it to the amount of the current period. in this case period 1 grnt_year 11
    so the expected outcome should be $700
    240055     240055     7240     4730     02     10     14     200
    240055     240055     7600     4730     02     10     14     100
    240055     240055     7600     4730     02     11     1     400keep in mind that im not given a year just a period.
    any help that you guys can offer would be immensely appreciated. I have been trying to get this to work for over 3 days now.
    finally broke down and put together this post
    Edited by: mlov83 on Sep 14, 2011 8:48 PM

    Frank
    wondering if you can help me modify this sql statement that you provided me with .
    table values have been modified a bit.
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');i need to take one more thing into consideration. if the greatest year has a value on period 00 i need to ignore the period 14 and the current period total would be
    the current period +(current period - greatest year 00)
    hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
    because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
    period 2 amount $ 600
    period 0 amount $ 400 - period 2 amount of $600 = 200
    600+200 = $800
    if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
    i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
    can you please help me out.
    Miguel

  • Need Help With Query Using Aggregation

    If I have a table, defined like this:
    CREATE TABLE range_test
    range_id NUMBER(20) NOT NULL,
    grade CHAR(1) NOT NULL,
    lower_bound_of_range NUMBER(5,2) NOT NULL,
    upper_bound_of_range NUMBER(5,2) NOT NULL,
    received_date_time_stamp TIMESTAMP DEFAULT SYSTIMESTAMP NOT NULL
    And I wanted to query the table to find the range associated with the last inserted row for each 'grade' (e.g. 'A', 'B', 'C', etc), how would I go about that?
    I want something like the following, but I know that this won't work right:
    SELECT
    grade,
    lower_bounding_of_range,
    upper_bounding_of_range,
    max(received_date_time_stamp)
    FROM
    range_test GROUP BY received_date_time_stamp;
    Thanks for your help. . .I'm frustrating myself with this one and I think it should be possible without having to use PL/SQL (i.e. SQL aggregate functions or sub-queries should work).

    Perhaps something along the lines of...
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, empno, ename, hiredate
      2  from emp
      3* order by deptno, empno
    SQL> /
        DEPTNO      EMPNO ENAME      HIREDATE
            10       7782 CLARK      09-JUN-1981 00:00:00
            10       7839 KING       17-NOV-1981 00:00:00
            10       7934 MILLER     23-JAN-1982 00:00:00
            20       7369 SMITH      17-DEC-1980 00:00:00
            20       7566 JONES      02-APR-1981 00:00:00
            20       7788 SCOTT      19-APR-1987 00:00:00
            20       7876 ADAMS      23-MAY-1987 00:00:00
            20       7902 FORD       03-DEC-1981 00:00:00
            30       7499 ALLEN      20-FEB-1981 00:00:00
            30       7521 WARD       22-FEB-1981 00:00:00
            30       7654 MARTIN     28-SEP-1981 00:00:00
            30       7698 BLAKE      01-MAY-1981 00:00:00
            30       7844 TURNER     08-SEP-1981 00:00:00
            30       7900 JAMES      03-DEC-1981 00:00:00
    14 rows selected.
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, empno, ename, hiredate
      2  from (
      3        select deptno, empno, ename, hiredate
      4              ,row_number() over (partition by deptno order by hiredate desc) as rn
      5        from emp
      6       )
      7  where rn = 1
      8* order by deptno, empno
    SQL> /
        DEPTNO      EMPNO ENAME      HIREDATE
            10       7934 MILLER     23-JAN-1982 00:00:00
            20       7876 ADAMS      23-MAY-1987 00:00:00
            30       7900 JAMES      03-DEC-1981 00:00:00
    SQL>

  • Need help with Query

    Hi,
    Good day everyone! I need help writing a query. I have this table with the following data in them...
    ACCT_CODE  FSYR      YTD_AMT
    A123            11          100  
    A456            11          200
    A123            10          50
    A456            10          100I want the output to look like this:
    ACCT_CODE     CURRENT_YEAR(11)       PRIOR_YEAR(10)
    A123               100                              50
    A456               200                              100The user will input the fiscal year and based on that input, I want to get the prior year value as well.
    Thank you for all your help!!
    Edited by: user5737516 on Jun 29, 2011 6:48 AM
    Edited by: user5737516 on Jun 29, 2011 6:50 AM

    user5737516 wrote:
    Hi,
    Good day everyone! I need help writing a query. I have this table with the following data in them...
    ACCT_CODE FSYR YTD_AMT
    A123 11 100
    A456 11 200
    A123 10 50
    A456 10 100
    I want the output to look like this:
    ACCT_CODE CURRENT_YEAR PRIOR_YEAR
    A123 100 50
    A456 200 100
    The user will input the fiscal year and based on that input, I want to get the prior year value as well.
    Thank you for all your help!!what is prior year?

  • Query off of Oracle using WinSql - Need help with query

    I am trying to query off of Oracle using program WinSql.
    I have a table(tticpr200110) that has the following sample data:
    ITEM     CODE     T$AMNT
    23500076 ACL     .0049
    23500076 APM     0
    23500076 APO     .0093
    23500076 EXP     .0001
    23500076 RES     .0072
    and what I want it to look like is:
    ITEM     ACL     APM     APO     EXP     RES
    23500076     0.0049     0     0.0093     0.0001     0.0072
    (actually I need the last 2 columns added together to be MATL-but can deal with that down the road).
    Seems simple enough, but I don't know to put into the columns.
    Any help would be GREATLY appreciated as soon as possible would be even better.

    My table - tticpr200110 when it runs I get the following sample data for part number 23500076:
    The first coloumn ITEM is the part number.
    The second column CODE is 1 of 5 different cost codes
    The third column is the cost for that code for that part.
    ITEM CODE AMNT
    23500076 ACL 0.0049
    23500076 APM 0.0000
    23500076 APO 0.0093
    23500076 EXP 0.0001
    23500076 RES 0.0072
    I want to make a query that makes the data look like this:
    ITEM ACL APM APO EXP RES
    23500076 0.0049 0.0000 0.0093 0.0001 0.0072
    (similar to a pivot table in excel or acess)
    I hope this helps better.
    Thanks!

  • Need help with Query to determine Credit Memos and Invoices

    Hi All
    Thanks for all the help here.
    I need a query to determine any credits or invoices issued within a given period.
    OINV and ORIN with UNION ALL?
    Please advise any help.
    Thank you!

    Hi Daniel,
    Please check below Query.
    SELECT T0.[DocNum] as 'Invice No', T0.[DocDate] as 'Invoice Date', T0.[CardName] as 'Invoiced Customer', T3.[DocNum] as 'Credit Memo No', T3.[DocDate] as 'Credit Mamo Date', T3.[CardName] as 'Credit Memo Customer' FROM OINV T0  LEFT JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry] LEFT JOIN RIN1 T2 ON T2.[BaseEntry] = T1.[DocEntry] AND T2.[BaseLine] =  T1.[LineNum] LEFT JOIN ORIN T3 ON T2.[DocEntry] = T3.[DocEntry] WHERE T0.[DocDate]  >=[%3]  AND   T0.[DocDate] <=[%4]
    Hope this helps
    Regards::::
    Atul Chakraborty

  • [Oracle 8i] Help with query performance

    The following query is running VERY slowly for me:
    SELECT     oord.part_nbr
    ,     sopn.ord_nbr
    ,     sopn.sub_ord_nbr
    ,     sopn.major_seq_nbr
    ,     sopn.wctr_id
    ,     sopn.oper_desc
    ,     SUM(pact.act_dlrs_earned+pact.act_brdn_dls_earned+pact.tool_dlrs_earned+pact.act_fix_brdn_dls_ea)
    ,     pact.activity_date
    FROM     PACT pact
    ,     SOPN sopn
    ,     OORD oord
    WHERE     pact.order_nbr          = sopn.ord_nbr          AND
         pact.maj_seq_nbr     = sopn.major_seq_nbr     AND
         sopn.sub_ord_nbr     = pact.sub_order_nbr     AND
         sopn.ord_nbr          = oord.ord_nbr          AND
         sopn.sub_ord_nbr     = oord.sub_ord_nbr     AND
              pact.activity_date     >= ?          AND
              sopn.rework_ind          = 'N'          AND
              (oord.part_nbr, sopn.major_seq_nbr, sopn.wctr_id)
              NOT IN     (
                        SELECT     rout.doc_nbr
                        ,     rout.major_seq_nbr
                        ,     rout.wctr_id
                        FROM ROUT rout
                        WHERE     (rout.begn_eff_dt    <=SYSDATE)     AND
                             (rout.end_eff_dt    >SYSDATE)     AND
                             (rout.po_rework_ind    ='N')       
    GROUP BY     oord.part_nbr
    ,          sopn.ord_nbr
    ,          sopn.sub_ord_nbr
    ,          sopn.major_seq_nbr
    ,          sopn.wctr_id
    ,          sopn.oper_desc
    ,          pact.activity_dateI sent a request off to my IT department (specifically asking for the explain plan and tkprof, as described in the [main post on this topic|http://forums.oracle.com/forums/thread.jspa?threadID=501834] ), and they replied with a screen shot of the 'explain plan' the tool they use (Toad) provides.
    !http://temp-sample.webs.com/explain_plan.jpg!
    I don't know if anyone can help me based off this, since I know it's not really what the main post says to provide, but it's all I was given.
    My IT department also made a few changes to my original query (see below) and told me it got rid of one of the full scans of the PACT table, but they aren't sure why it helped, and I have to say I'm suspect of any fixes where it's not understood why it helped.
    SELECT     oord.part_nbr
    ,     sopn.ord_nbr
    ,     sopn.sub_ord_nbr
    ,     sopn.major_seq_nbr
    ,     sopn.wctr_id
    ,     sopn.oper_desc
    ,     SUM(pact.act_dlrs_earned+pact.act_brdn_dls_earned+pact.tool_dlrs_earned+pact.act_fix_brdn_dls_ea)
    ,     pact.activity_date
    FROM     PACT pact
    ,     SOPN sopn
    ,     OORD oord
    WHERE     sopn.ord_nbr          = pact.order_nbr     AND
         sopn.major_seq_nbr     = pact.maj_seq_nbr     AND
         pact.sub_order_nbr     = sopn.sub_ord_nbr     AND
         oord.ord_nbr           = sopn.ord_nbr          AND
         oord.sub_ord_nbr     = sopn.sub_ord_nbr     AND
         (pact.activity_date >= ?)               AND
         'N'               = sopn.rework_ind     AND
         pact.order_nbr          = oord.ord_nbr          AND
         oord.sub_ord_nbr = pact.sub_order_nbr          AND
         (oord.part_nbr, pact.maj_seq_nbr, sopn.wctr_id) NOT IN
              SELECT /*+ INDEX_JOIN(ROUT) */     rout.doc_nbr
              ,                    rout.major_seq_nbr
              ,                    rout.wctr_id
              FROM     ROUT rout
              WHERE     rout.begn_eff_dt     <= SYSDATE     AND
                   rout.end_eff_dt      > SYSDATE     AND
                   'N' = rout.po_rework_ind
    GROUP BY     oord.part_nbr
    ,          sopn.ord_nbr
    ,          sopn.sub_ord_nbr
    ,          sopn.major_seq_nbr
    ,          sopn.wctr_id
    ,          sopn.oper_desc
    ,          pact.activity_dateAny help on this would be appreciated... when I run this (right now) for 2-3 months of data, it takes a minimum of 3 hours to complete, and I'll eventually need to run this for up to a year's worth of data.

    Hi,
    Well, let's see.
    You get 156 rows returned using IN and 121 rows using exists.
    You need identify the 'missing records' and conclude if that's correct or not, I'm not able to do that from remote, without knowing your data or system.
    It would be helpful if we could see cost and cardinalities, you (or your IT dept.) can get them easily be running the queries from your SQL*Plus prompt.
    Type
    SET AUTOTRACE TRACEONLYbefore running the queries.
    That gives you the explain plan and additional statistics (sorts in memory and sorts to disk).
    Since you use a group by, and you're on 8i can you also post results of these queries:
    select banner from v$version;
    select name, value, isdefault from v$parameter where name like '%area%';Finally, does below query give you a different plan?
    select oord.part_nbr
    ,      oord.ord_nbr
    ,      oord.sub_ord_nbr
    ,      pact.major_seq_nbr
    ,      sopn.wctr_id
    ,      sopn.oper_desc
    ,      sum(pact.act_dlrs_earned + pact.act_brdn_dls_earned + pact.tool_dlrs_earned + pact.act_fix_brdn_dls_ea)
    ,      pact.activity_date
    from   oord oord 
    ,      pact pact
    ,      sopn sopn
    where  oord.ord_nbr       = pact.order_nbr
    and    oord.sub_ord_nbr   = pact.sub_order_nbr
    and    oord.ord_nbr       = sopn.ord_nbr
    and    oord.sub_ord_nbr   = sopn.sub_ord_nbr
    and    sopn.major_seq_nbr = pact.maj_seq_nbr
    and    (pact.activity_date >= ?)
    and    'N' = sopn.rework_ind
    and    (oord.part_nbr, pact.maj_seq_nbr, sopn.wctr_id) not in ( select rout.doc_nbr
                                                                    ,      rout.major_seq_nbr
                                                                    ,      rout.wctr_id
                                                                    from   rout rout
                                                                    where  rout.begn_eff_dt <= sysdate
                                                                    and    rout.end_eff_dt > sysdate
                                                                    and    'N' = rout.po_rework_ind)
    group  by oord.part_nbr
    ,         oord.ord_nbr
    ,         oord.sub_ord_nbr
    ,         pact.major_seq_nbr
    ,         sopn.wctr_id
    ,         sopn.oper_desc
    ,         pact.activity_date

  • Help with pricing condition??

    Hi Guyz,
    I have a requirement with my client, the want to supply material to an external customer at an intercompany price(ZPR9). So whenever a sales order is created for this specific customer it should pull the price from Intercompany price(ZPR9).  I have a option to create new pricing procedure and new pricing condition but this condition should pick up the price from ZPR9 so that we don't have to define the price manually like we do in PR00.
    I can't able to assign ZPR9 to my new pricing procedure because ZPR9 is use for intercompany and this customer doesn not belong to any of our company code.So the situation is i have to define new pricing procedure and new pricing condition but this condition should pull the price from ZPR9.
    when I see the details of ZPR9(condition type) its condition category is assigned as 'Y' which is customer reserve Y. I am not sure what this is.So could you plz advice how to handle this whole scenario. Appreciate your help.
    thanks
    Mohammed.

    mohammed,
    This type of requirement is hard to handle and if you do it in a wrong way, whoever support this process later will have a hard time.
    Anyway, I think one of the twisted ways of doing this is to use Alternative Culculation routine and put the logic to get the condition right out of price condition table (A*) of ZPR9. This is not flexible at all because this involves hard coding, so I do not recommend this.
    The message I can get from your client is "We don't want to maintain the same condition here and there," but sometimes they have to deal with it, because the nature of the condition type is very different from business point of view.
    Having said that, in order for them to have easier way to create the condition, maybe you can develop a custom ABAP to copy ZPR9 condition into the new condition you might be creating, and either have them run the program every time they update ZPR9 or schedule the job.
    Hope this helps.
    Akio

Maybe you are looking for