Help With Query Performance

Hi Everyone,
I have to query a table that stores daily information and I only need to get the current month's data out of there. There is A LOT of data in there (4 years X 15 stores X 65 depts). I was wondering if there was a way to get the current month's data fast. Now it's extremely slow, 5 mins to query, and my users can't wait that long.
Any sugguestions
Thank You
-Sam

Assuming that emp_id is the PK of emp, then you do not need the MAX on the data from emp. Also you really do not need to put conditions against sysdate. If you only want the records for the current month, then this should work:
SELECT TO_CHAR(cms_bh_dagent.row_date, 'mm/yyyy') row_date,
       emp.id, emp.short_name, emp.dept_code, emp.descr,
       SUM(cms_bh_dagent.ti_stafftime) AS ti_stafftime,
       SUM(cms_bh_dagent.ti_availtime) AS ti_availtime,
       SUM(cms_bh_dagent.acdcalls) AS acdcalls,
       SUM(cms_bh_dagent.acdtime) AS acdtime,
       SUM(cms_bh_dagent.acwtime) AS acwtime,
       SUM(cms_bh_dagent.holdcalls) AS holdcalls,
       SUM(cms_bh_dagent.holdtime) AS holdtime,
       SUM(cms_bh_dagent.ti_auxtime0) AS ti_auxtime0
FROM cms_bh_dagent
        INNER JOIN emp ON cms_bh_dagent.logid = emp.acd_login_id
WHERE cms_bh_dagent.row_date BETWEEN TRUNC(sysdate, 'MONTH') AND
                                     LAST_DAY(TRUNC(sysdate)) and
      emp.code = :tlcode
GROUP BY TO_CHAR(cms_bh_dagent.row_date, 'mm/yyyy'),
         emp.id, emp.short_name, emp.dept_code, emp.descrIt seems to me that an index on emp.code might be useful in this query, as well as one on cms_bh_dagent (logid , row_date).
If you want to be able to specify the from and to date, then replace the predicate on cms_bh_dagent.row_date with:
BETWEEN TO_DATE(start_date, 'your_format') AND TO_DATE(end_date, 'your_format')
HTH
John

Similar Messages

  • [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

  • Issue with query performance

    Hi,
    I have a multi provider with 2 cubes & 3 ODS & 1 info object.
    On top of this MP queries are built. All the queries are in 3.5
    It takes more then 30 min to execute each query.
    Now we are planning to replace all 3.5 queries in 7.
    We will build cube on top of 3 ODS. New MP will have 3 cubes & 1 Info object.
    My issue is, the other 2 cubes are too large. We have around 4 million records in each.
    And i need only few fields from these cubes.
    Is there any way I can have less load on MP?
    What would be the best approach to improve query performance?
    Thanks,
    Gowri

    Hello Gowri,
    I think you should take the help of Aggregates.
    You may create aggregates on the 2 large cube, using the characteristics
    that you are using in the Query.
    Since that cubes are having large amount of data, the use of aggregates will consideraly
    reduce the Data manager time i.e. time spent by the query in retriving data from info-provider.
    for more details on aggregates please refer the following link:
    http://help.sap.com/saphelp_nw04/helpdata/en/7d/eb683cc5e8ca68e10000000a114084/content.htm
    Thanx and regards
    Priyanka

  • 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.

  • Problem with query performance

    Hi All,
    While loading data if we run the report, will it make any difference in the query performance? I have a cube with 230 million records  I am running the delta which has got another 230 million records. Now I am trying to run the queries on the cube, all those timed out.
    But I have a DSO with the 480 million the same queries are running good on the DSO. But I wanted to run the reports on the cube not on DSO what can I do? Is the data load giving any problem in the query runtime??
    Pleas advise me what to do?
    Regards
    Kiran

    Hi,
    My load got finished, Now i created indexes and tried to run the query, every query on this cube times out.. but on the top of DSO we have Same queries those queries are running.. what could be the reason how can i go ahead to improve the query performance plzzz advise me
    Kiran
    Edited by: kiran kumar on Mar 14, 2009 1:28 AM

  • Help with query optimization

    Right now my query takes anywhere from 30 to 60 sec's to execute. What should I do to cut this time down?
    Here is my Query
    select * from a , b, c
    where a.a_seq = b.b_seq
    and a.a_seq = c.c_seq
    and a.a_type between 3 and 19
    and a.detl_cod = 'AV'
    and b.detl_stat = 'CLD'
    and c.date is not null
    and c.id != 92342
    these tables have 100 thousand rows each. What should I be looking at to cut down the execution time on this query?

    Sorry, I am fairly new to SQL. I can write queries but, I have no idea where to even begin with when it comes to checking performance. What are the statistics that you are mentioning? how will it effect performance? and what about indexed attributes? there are a lot of indexed attrinutes on each of these tables. I am unable to give you the exact tables because it is production application code(Cofidential).
    I really appreciate any help from you
    Thank you.

  • 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

  • Need Help with site performance

    Looking for Help..
    In particular we would like help from experts in ssl, browser experts
    (how browsers handle encryption, de-encryption), iPlanet experts, Sun
    crypto card experts, webdesign for performance experts.
    Our website is hosted on a Sun Enterprise 450 server running Solaris v7
    The machine is hosted at Exodus. These are the following software
    servers that perform the core functions of the website:
    iPlanet Web Server v. 4.1 ( Java server is enabled)
    IBM db2 v. 7.1
    SAA uses SmartSite, a proprietary system developed by Adaptations
    (www.adaptations.com). At the level of individual HTML pages, SmartSite
    uses
    proprietary markup tags and Tcl code embedded in HTML comments to
    publish
    content stored in a database. SmartSite allows for control over when,
    how and
    to whom content appears. It is implemented as a java servlet which
    stores its data on the db2 server and uses a tcl like scripting language
    (jacl- orginally developed by Sun)
    CHALLENGE:
    In late June this year we launched a redesigned website with ssl enabled
    on all pages. (a departure from the previous practice of maintaining
    most of the site on non-secure server and only some pages on a ssl
    server). We also introduced a new website design with greater use of
    images, nested tables and javascript.
    We have found that the introduction of the "secure everywhere" policy
    has had a detrimental effect on the web site user experience, due to
    decreased web server and web browser performance. In other words, the
    site got slower. Specifically, we have
    identified the following problems:
    1. Web server performance degradation. Due to unidentified increases in
    web
    server resource demand caused (probably) by the global usage of SSL, the
    web
    server experienced instability. This was resolved by increasing the
    amount of
    operating system (OS) resources available to the server.
    2. Web browser performance degradation. Several categories are noted:
    2.1. Page load and rendering. Page load and rendering time has
    increased dramatically on the new site, particularly in the case of
    Netscape Navigator. Some of this may be attributed to the usage of SSL.
    Particularly, the rendering time of complex tables and images may be
    markedly slower on slower client machines.
    2.2. Non-caching of content. Web browsers should not cache any content
    derived from https on the local hard disk. The amount of RAM caching
    ability varies form browser to browser, and machine to machine, but is
    generally much less than for disk caching. In addition, some browser may
    not cache content in RAM cache at all. The overall effect of reduced
    caching is increased accesses to the web server to retrieve content.
    This
    will degrade server performance, as it services more content, and also
    web browser performance, as it will spend more time waiting for page
    content before and while rendering it.
    Things that have been attempted to improve performance:
    1) Reducing javascript redundancy (less compiling time required)
    2) Optimizing HTML code (taking out nested tables, hard coding in specs
    where possible to reduce compiling time)
    3) Optimizing page content assembly (reducing routine redundancy,
    enabling things to be compiled ahead of time)
    4) Installing an encryption card (to speed page encryption rate) - was
    removed as it did not seem to improve performance, but seemed to have
    degraded performance

    Fred Martinez wrote:
    Looking for Help..
    In particular we would like help from experts in ssl, browser experts
    (how browsers handle encryption, de-encryption), iPlanet experts, Sun
    crypto card experts, webdesign for performance experts.
    Our website is hosted on a Sun Enterprise 450 server running Solaris v7
    The machine is hosted at Exodus. These are the following software
    servers that perform the core functions of the website:
    iPlanet Web Server v. 4.1 ( Java server is enabled)
    IBM db2 v. 7.1
    SAA uses SmartSite, a proprietary system developed by Adaptations
    (www.adaptations.com). Since I don't see iPlanet's application server in the mix here this (a
    newsgroup
    for performance questions for iAS) is not the newsgroup to ask in.
    Kent

  • Help with Video Performance Issues using Flash

    Asking on behalf of a customer who has been unable to get any answers so far - are you able to help?
    Background:
    We have a port of our Game Development Kit which allows us to recompile all our games using Crossbridge (http://adobe-flash.github.io/crossbridge/) into SWF without any code modifications.
    Overview:
    Our framework is using OpenGL for rendering and we have successfully ported it along with the audio and video to run in Flash.
    We are experiencing performance issues using Video. We cannot use image sequence as some of the video animations are too long and would increase the download to an unacceptable size.  Assets vary between 256x256 - 1024x1024 videos.

    Here's the rest of the story.  Let me know if you can see any resolution, and I will connect him to the forums.  Thank you.
    Current Video Solution:
    We create an instance of NetConnection, NetStream, and Video according to most samples out there, and invoke draw to rasterize the Video DisplayObject into a BitmapData instance.
    The BitmapData instance has a fixed color component layout which is not compatible with Stage3D texture and is therefore has to be reformatted before uploaded to Stage3D Texture (See Code Listing below).
    Our Problems:
    Performance issues with RGBA conversion (either using copyChannel or manually reformatting is not fast enough) natively in as3; this required for stage3d texture.Copying each channel individual using bitmapdata.Copychannel seems faster, but not significantly faster.
    Cannot detect when video frame has been updated, therefore we may copy pixels that are not needed in enterframe (processpixel).
    Looping video, our current solution uses the NET_STATUS event Buffer empty; Is there a better way to loop videos than checking buffer and seeking to 0.
    Stepping video, loading FLV or MP4 side by side assets from HTTP or embedded does not support stepping? Is there another way?
    ActionScript Code Listing:
    video_nc = new NetConnection();
    video_nc.addEventListener(NetStatusEvent.NET_STATUS , onConnect);
    video_nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR , trace);
    video_nc.connect(null);
    // OnConnect Event:
    this.ns = new NetStream(e.target as NetConnection);
    eventclient = new Object();
    eventclient.onMetaData = onMetaData;
    this.ns.client = eventclient;
    ns.play(flvfile);
    ns.pause();
    //onMetaData event:
    this.width = infoObject.width;
    this.height = infoObject.height;
    this.textureWidth = NextPowerOfTwo(this.width);
    this.textureHeight = NextPowerOfTwo(this.height);
    cliprect = new Rectangle(0, 0, this.width ,this.height);
    cliprect.x = 0;
    cliprect.y = 0;
    cliprect.width = this.textureWidth;
    cliprect.height = this.textureHeight;
    totalFrames = infoObject.duration * infoObject.fps;
    this.hasAlpha = true;
    if(infoObject.videocodecid == 5)
    this.hasAlpha = true;
    this.bitmapData = new BitmapData(this.textureWidth, this.textureHeight, hasAlpha, 0xff000000);
    this.video = new Video(this.width, this.height);
    this.video.attachNetStream(ns);
    this.video.addEventListener(Event.ENTER_FRAME, processPixels);
    // processPixel method:
    BitmapData.draw(video);
    GLAPI.instance.glBindTexture(GLAPI.GL_TEXTURE_2D,this.textureId);
    var fmt:uint = GLAPI.GL_ARGB;
    // converting pixels using copychannel or loop through pixels
    GLAPI.instance.glBindTexture(GLAPI.GL_TEXTURE_2D,this.textureId);
    GLAPI.instance.glTexImage2D(GLAPI.GL_TEXTURE_2D, 0, fmt, this.textureWidth, this.textureHeight, 0,fmt, GLAPI.GL_UNSIGNED_BYTE, 0, convBitmapData.getPixels(cliprect));

  • 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!

Maybe you are looking for

  • ILife 11 Disc no longer available at the Apple Store

    Went to the Apple Store this morning to get the URL for the iLife 11 disk page and found it was no longer available.  Therefore, any user who needs to purchase a copy of iWeb will have to go to Amazon.com or eBay.com. OT

  • Profit Center Accounting - 3KEH

    We have added a Balance Sheet Account to 3KEH to be tracked in PCA. How do I go about getting the history of that account into PCA? Edited by: April Browder on Jan 10, 2009 1:03 AM

  • Remove Duplicates in string sql AND TAKE THE CORRECT ONE

    Good Evening how can i perform this task with ssis  OR TRANSACT SQL?  I HAVE THESE ROWS WITH THE NEXT DATA, I want to take just the valid one, BUT I HAVE A LOT OF COMBINATIONS AS following names, it can be animals, things or personal names GABRIEL OB

  • How do I convert fh11 to ai (version AI CC 2014.0.0 18.0.0)

    Im in great need to convert fh11 to ai. If anyone know please let me know.

  • Gen 5 airport extreme

    Bought this in Nov 2012. great until yesterday. I have two windows pcs (one win 7 and one win 8) i-pad, 2006 macbook,and laptop using Ubuntu. All on wireless.  Both windows pcs speedtested at .08Mbs while the macbook and Ubuntu speedtested at 24Mbs.