Help with query: monthly accumulated sales by month

Hi,
i need to build a query that shows two key figures:
KF1) Sales accumalated on last 60 months.
KF2) Sales for actual month.
i know i can solve this using selections, the problem is my client needs it on columns for each month selected
from a range. For example:
Selecting months 01.2009 - 04.2009:
01.2009 | 02.2009 | 03.2009 | 04.2009
KF1|KF2 | KF1|KF2 | KF1|KF2 | KF1|KF2
KF2 appears by default, but is it possible to show KF1 using selections ?

Hola Juan Pablo.
Here the main problem I see is the possibility of select a range for the 0CALMONTH. First of all try to speak to your customer to agree the possibility of select in the variables the "Ending/Last" 0CALMONTH. If you can achieve this the rest is more  o less easy.
You have to define an structure o several RKF and from 0CALMONTH you make a set of variables (post-popop) to restric them:
RKF_1M_01  (Selected Month)
RKF_1M_60  (Selected Month) - (offset - 60)
RKF_2M_01  (Selected Month -1 )
RKF_2M_60  (Selected Month -1 ) - (offset - 60)
RKF_3M_01  (Selected Month -2 )
RKF_3M_60  (Selected Month -2 ) - (offset - 60)
RKF_4M_01  (Selected Month -3 )
RKF_4M_60  (Selected Month -3 ) - (offset - 60)
I've made something similar for Balance Sheet
Hope it helps you.
Regards

Similar Messages

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

  • Help With Splitting Months / Hours

    Post Author: shmoov
    CA Forum: Formula
    Hi all - this is my first post to the forum...I am trying to create a report based on data I pull from a MS-SQL backend database.  The data I'm pulling is based on projects my employees are working on and/or are scheduled to perform.  Each of those projects has a certain amount of man hours assigned to it to complete.  What I'm trying to do is create an employee capacity chart that shows over the course of the next twelve months, how many man hours for each month are required to get our projects done - I use this to project new hires. Anyway, I have no problem creating the chart, but it's not as accurate as I'd like.  The four fields I'm pulling from the database for each project are START_DATE, END_DATE, MANHOURS, and STATUS.  The chart I've created bases the man hours on the start date, then sums all of the manhours up for the month, creating a bar graph by month.  My problem is that if a project stretches out over a month-end boundary - say, it starts on March 28th and goes to April 15th, I want to be able to split that up amongst the two months.  I'm able to get the numbers on this through the following formula snippet:if ((month ({@ConvertStartDate})) < (month ({@ConvertEndDate}))) then   // Does the project only span over two months?    if (month ({@ConvertEndDate}) - month ({@ConvertStartDate})) = 1 then         //See how many days the project is scheduled for        (TotalDaysOfProject := (DateDiff ("d", {@ConvertStartDate}, {@ConvertEndDate}) + 1);        //See how many days we have left in start month        DaysLeftInMonth := (DateDiff ("d", {@ConvertStartDate}, DateAdd ('m', 1, ({@ConvertStartDate}) - day({@ConvertStartDate}) + 1) - 1) + 1);        HoursForThisMonth := {@ChangeHoursToNumber} * (DaysLeftInMonth / TotalDaysOfProject);        HoursForNextMonth := {@ChangeHoursToNumber} - HoursForThisMonth);So, what I want to do as each row is read in is make this evaluation - if it does span two months, I want it to print out two rows...For instance, instead of:START                END                MANHOURS                STATUS3/28/2008           4/15/2008        120                                Scheduled I would like it to print the following: START                END                MANHOURS                STATUS3/28/2008        3/31/2008        25.26                                Scheduled4/1/2008        4/15/2008        94.74                                    Scheduled  I know it sounds like a lot...Is it possible?  Thanks!

    Post Author: V361
    CA Forum: Formula
    You could insert another detail section (or group if that is the level you are working on)
    Use this formula to determine if you have spanned more than one month.
    month() - month()                            {@MTAM}
    The result can be used to supress / not supress various sections.
    You can then use this formula to get the last day of the month   {@ldofM}
    //Crystal syntax
    Local DateTimeVar d := {Sheet1_.Start_DATE};
    DateSerial(Year(d), Month(d) + 1, 1 - 1)
    Use this one to get the first day on the next month.              {@1stdofM}
    //Crystal syntax
    Local DateTimeVar d := {Sheet1_.Start_DATE};
    DateSerial(Year(d), Month(d) + 1, 1 - 0)
    You can then use those formulas to display your days difference.  Put your
    startdate   {@ldofM}
    {@1stdofM} enddate
    in your new detail section, and set to display if {@MTAM} = 1 
    hope this helps.

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

  • Requesting help with query

    Well the idiots that designed this database table that I'm working with decided to store dates in a NUMBER(8) field in the format of YYYYMMWW -- that's the year+month+week of year.
    If I have records such as:
    PERIOD     EMPID     REVENUE
    20070626     11122     396080.77
    20070727     11122     399667.83
    20070728     11122     409765.94
    20070729     11122     430246.10
    20070730     11122     437611.86
    20070831     11122     463508.75
    20070832     11122     468487.00
    How can I get a query result to look as this:
    PERIOD     EMPID     REVENUE
    20070626     11122     396080.77
    20070730     11122     437611.86
    20070832     11122     468487.00
    The output should only have the last record from each month.

    Maybe something like:
    SQL> WITH test_tab AS
      2       (SELECT 20070626 period, 11122 empid, 396080.77 revenue
      3          FROM DUAL
      4        UNION ALL
      5        SELECT 20070727, 11122, 399667.83
      6          FROM DUAL
      7        UNION ALL
      8        SELECT 20070728, 11122, 409765.94
      9          FROM DUAL
    10        UNION ALL
    11        SELECT 20070729, 11122, 430246.10
    12          FROM DUAL
    13        UNION ALL
    14        SELECT 20070730, 11122, 437611.86
    15          FROM DUAL
    16        UNION ALL
    17        SELECT 20070831, 11122, 463508.75
    18          FROM DUAL
    19        UNION ALL
    20        SELECT 20070832, 11122, 468487.00
    21          FROM DUAL)
    22  SELECT period, empid, revenue
    23    FROM (SELECT period,
    24                 ROW_NUMBER () OVER (PARTITION BY TO_NUMBER
    25                                                    (SUBSTR (TO_CHAR (period),
    26                                                             5,
    27                                                             2
    28                                                            )
    29                                                    ) ORDER BY TO_NUMBER
    30                                                       (SUBSTR (TO_CHAR (period),
    31                                                                7
    32                                                               )
    33                                                       ) DESC) rn,
    34                 empid, revenue
    35            FROM test_tab)
    36   WHERE rn = 1
    37  /
        PERIOD      EMPID    REVENUE
      20070626      11122  396080.77
      20070730      11122  437611.86
      20070832      11122     468487
    3 rows selected.
    SQL> Regards,
    Jo

  • 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

  • Help with query to determine if a record value has changed.

    Our auditors want to know which items had their costs updated in March 2006. I'm querying the cst_standard_cost table to find records that were updated in March. This part seems to be working although it pulls back multiple rows for the same item if more than one update was done in that month. I'm still not sure how I'm going to handle that problem.
    ----cst_standard_costs-----
    alter session set NLS_DATE_FORMAT = 'MM/DD/YYYY';
    drop table suss.cost_update_0306b;
    create table suss.cost_update_0306b
    as
    select csc.inventory_item_id, mtl.segment1||','||mtl.segment2 "item", csc.organization_id,csc.standard_cost,csc.creation_date "creation_date"
    from cst_standard_costs csc, mtl_system_items_b mtl
    where csc.inventory_item_id = mtl.inventory_item_id
    and mtl.organization_id = '82'
    and csc.organization_id not in ('0','81')
    and csc.creation_date like '03/%/2006%'
    order by csc.inventory_item_idHere, I'm trying to find if the update that was done in March actually changed the item's cost. But the sql is not exactly right. The results being returned are any cost update where the item's cost is different than it was in March. I'd like to pull back the item's cost from the most recent cost update previous to the March update and see if it differs from the March cost.
    select csc.inventory_item_id,mtl.segment1||','||mtl.segment2, csc.organization_id,csc.standard_cost, csc.creation_date
    from cst_standard_costs csc, mtl_system_items_b mtl, suss.cost_update_0306b scu
    where csc.inventory_item_id = mtl.inventory_item_id
    and mtl.organization_id = '82'
    and scu.inventory_item_id = csc.inventory_item_id
    and csc.organization_id not in ('0','81')
    and csc.creation_date < scu."creation_date"
    and csc.standard_cost <>scu.standard_cost
    order by csc.inventory_item_id ascHere's a simple example
    item id.....cost.........update_date
    24..........45.00........03/01/2006
    24..........45.00........02/01/2006
    24..........30.00........02/22/2006
    40..........45.00........03/01/2006
    40..........30.00........02/01/2006
    40..........28.00........02/22/2006
    The results of the sql should be to return item id 40 because the costs changed in March but not item id 24 because the costs did not change in March

    Something like this:
    SQL> DESC COSTS;
    Name                                      Null?    Type
    ITEM_ID                                            NUMBER
    COST                                               NUMBER(4,2)
    UPDATE_DATE                                        DATE
    SQL> SELECT * FROM COSTS;
       ITEM_ID       COST UPDATE_DAT
            24         40 03/01/2006
            24         45 02/01/2006
            40         45 03/01/2006
            40         30 02/01/2006
    SQL> SELECT b.item_id, b.cost, b.update_date
      2  FROM costs a, costs b
      3  WHERE a.item_id = b.item_id
      4   AND a.cost <> b.cost
      5   AND a.update_date = ADD_MONTHS(b.update_date, -1)
      6  /
       ITEM_ID       COST UPDATE_DAT
            24         40 03/01/2006
            40         45 03/01/2006It is maybe not efficient query but works :)
    Another solution:
      1  SELECT a.item_id, a.cost, a.update_date
      2  FROM costs a
      3  WHERE a.cost <> (SELECT cost
      4               FROM costs
      5               WHERE a.item_id = item_id
      6                AND ADD_MONTHS(a.update_date, -1) = update_date
      7*            )
    SQL> /
       ITEM_ID       COST UPDATE_DAT
            24         40 03/01/2006
            40         45 03/01/2006Peter D.

  • 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 urgent help with query....

    i need to print loc field with it but the logic is get ti loc code where the month is maximum...
    Need output like this
    K  Loc            M_1        M_2        M_3        M_4        M_5        M_6
    A   1     2.5        4.5          0          0          0          0
    B   4        0          0          0          0        2.5          0
    C  3       2.5        2.5        2.5        2.5        2.5        2.5
    drop table y;
    create table y( key char(1),
              loc number,
              month char(2),
              amnt number);
    insert into y values('A',2,'01',2.50);
    insert into y values('A',1,'02',4.50);
    insert into y values('B',4,'05',2.50);
    insert into y values('C',2,'01',2.50);
    insert into y values('C',8,'02',2.50);
    insert into y values('C',3,'03',2.50);
    insert into y values('C',3,'04',2.50);
    insert into y values('C',3,'05',2.50);
    insert into y values('C',3,'06',2.50);
    commit ;
    select key
    ,sum(decode(month,'01',amnt,0)) m_1
    ,sum(decode(month,'02',amnt,0)) m_2
    ,sum(decode(month,'03',amnt,0)) m_3
    ,sum(decode(month,'04',amnt,0)) m_4
    ,sum(decode(month,'05',amnt,0)) m_5
    ,sum(decode(month,'06',amnt,0)) m_6
    from y
    group by key;
    SQL> select key
      2  ,sum(decode(month,'01',amnt,0)) m_1
      3  ,sum(decode(month,'02',amnt,0)) m_2
      4  ,sum(decode(month,'03',amnt,0)) m_3
      5  ,sum(decode(month,'04',amnt,0)) m_4
      6  ,sum(decode(month,'05',amnt,0)) m_5
      7  ,sum(decode(month,'06',amnt,0)) m_6
      8  from y
      9  group by key;
    K        M_1        M_2        M_3        M_4        M_5        M_6
    A        2.5        4.5          0          0          0          0
    B          0          0          0          0        2.5          0
    C        2.5        2.5        2.5        2.5        2.5        2.5

    Well, maybe I'm lucky to understand here ?
    SQL> select
    2   key
    3  ,max(loc) keep (dense_rank last order by
    amnt,month) loc
    4  ,sum(decode(month,'01',amnt,0)) m_1
    5  ,sum(decode(month,'02',amnt,0)) m_2
    6  ,sum(decode(month,'03',amnt,0)) m_3
    7  ,sum(decode(month,'04',amnt,0)) m_4
    8  ,sum(decode(month,'05',amnt,0)) m_5
    9  ,sum(decode(month,'06',amnt,0)) m_6
    10  from y
    11  group by key;
    K        LOC        M_1        M_2        M_3
    M_4        M_5        M_6
    A          1        2,5        4,5          0
    0          0          0
    4          0          0          0          0
    2,5          0
    3        2,5        2,5        2,5        2,5
    2,5        2,5Nicolas.
    This should be more a question for SQL and PL/SQL
    Forum :
    PL/SQL
    start=0
    Message was edited by:
    N. GasparottoPerfect..... many thanks... and i am sorry i put this in this forum rather than in SQL/PLSQL... but you are the best!!
    thanks to all of you..

  • 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