A tricky question on Grouping sets....

Hi All,
I have a weird requirement and table as folows:
Per_strt        Per_end     Per_desc        empid   Combo       sales
1-Dec-2008      1-Dec-2008  Day             1000    1           100
1-Dec-2008      1-Dec-2008  Day             1000    2           200
2-Dec-2008      2-Dec-2008  Day             1000    1           100
2-Dec-2008      2-Dec-2008  Day             1000    2           200
31-Dec-2008     31-Dec-2008  Day            1000    1           100
31-Dec-2008     31-Dec-2008  Day            1000    2           200
1-Dec-2008      31-Dec-2008  Month          1000    1           1000
1-Dec-2008      31-Dec-2008  Month          1000    2           2000
1-Jan-2009      1-Jan-2009  Day             1000    1           100
1-Jan-2009      1-Jan-2009  Day             1000    2           200
2-Jan-2009      2-Jan-2009  Day             1000    1           100
2-Jan-2009      2-Jan-2009  Day             1000    2           200
31-Jan-2009     31-Jan-2009  Day            1000    1           100
31-Jan-2009     31-Jan-2009  Day            1000    2           200
1-Jan-2009      31-Jan-2009  Month          1000    1           1000
1-Jan-2009      31-Jan-2009  Month          1000    2           2000
1-Feb-2009      1-Feb-2009  Day             1000    1           100
1-Feb-2009      1-Feb-2009  Day             1000    2           200
2-Feb-2009      2-Feb-2009  Day             1000    1           100
2-Feb-2009      2-Feb-2009  Day             1000    2           200
28-Feb-2009     28-Feb-2009  Day            1000    1           100
28-Feb-2009     28-Feb-2009  Day            1000    2           200
1-Feb-2009      28-Feb-2009  Month          1000    1           1000
1-Feb-2009      28-Feb-2009  Month          1000    2           2000
------------------------------------------------------------------------------------------------Now I want to generate a Year to Date record for Feb for the current year for each of employees for each combo
Also a weekly row for each week and here the issue is week can cross year and months
Per_strt        Per_end         Per_desc        empid   Combo       sales
01-Jan-2009     28-Feb-2009     Year            1000    1           6000
01-Jan-2009     28-Feb-2009     Year            1000    2           6000
26-Dec-2008     02-Jan-2009     Week            1000    1           1500
26-Dec-2008     02-Jan-2009     Week            1000    2           2500similiarly a YTD for Jan and similiarly for other weeks..... The start of the week is considered to be sundays and end on saturdays
Thanks and Regards,
Saff
How to achieve this using a single query?

The first week 2009 : start 28-12-2008    end : 03-01-2009
Solution
select *
from  T
model
return updated rows
partition by (empid,combo,case when per_desc='Day' then   TO_char(per_strt+1,'iw')  else '99' end as  pp, case when  to_char(PER_STRT,'mm')='12' and  TO_char(per_strt+1,'iw')='01'  then extract( year from PER_STRT) +1 else extract( year from PER_STRT)  end   yy )
dimension by(row_number()over(partition by empid,combo,case when per_desc='Day' then   TO_char(per_strt+1,'iw') else '99' end  order by PER_STRT) rn)
measures(PER_STRT, PER_END,PER_Desc, sales somme)ignore nav
rules
upsert
iterate(100)
until(presentv(PER_STRT[iteration_number+2],1,0)=0)
( somme[0]=somme[0]+somme[iteration_number+1],
PER_Desc[0]=case when PER_Desc[iteration_number+1] ='Day'  then 'Week' else 'Year'  end ,
PER_STRT[0]=min(PER_STRT)[any],
PER_end[0]=max(PER_end)[any]  )
order by empid,combo,PER_Desc,per_strt
/To resolve the problem to_char(sysdate,'iw') you just put to_char(sysdate+1,'iw') = First day of the week is sunday
SQL> edit
Wrote file afiedt.buf
  1*  select to_char(to_date('2008-12-27','yyyy-mm-dd')+1,'iw') from dual
SQL> /
TO
52
SQL> select to_char(to_date('2008-12-28','yyyy-mm-dd')+1,'iw') from dual;
TO
01
SQL> select to_char(to_date('2008-12-29','yyyy-mm-dd')+1,'iw') from dual;
TO
01
SQL>  select to_char(to_date('2008-12-26','yyyy-mm-dd')+1,'iw') from dual;
TO
52
SQL>  select to_char(to_date('2008-11-30','yyyy-mm-dd')+1,'iw') from dual;
TO
49
SQL> select to_char(to_date('2009-01-03','yyyy-mm-dd')+1,'iw') from dual;
TO
01
SQL> select to_char(to_date('2009-01-04','yyyy-mm-dd')+1,'iw') from dual;
TO
02
SQL>
DEmo
SQL> select * from t order by empid,combo,PER_Desc,per_strt;
PER_STRT  PER_END   PER_D      EMPID      COMBO      SALES
01-DEC-08 01-DEC-08 Day         1000          1        100
02-DEC-08 02-DEC-08 Day         1000          1        100
28-DEC-08 28-DEC-08 Day         1000          1        500
29-DEC-08 29-DEC-08 Day         1000          1         50
31-DEC-08 31-DEC-08 Day         1000          1        100
01-JAN-09 01-JAN-09 Day         1000          1        100
02-JAN-09 02-JAN-09 Day         1000          1        100
30-JAN-09 30-JAN-09 Day         1000          1        500
31-JAN-09 31-JAN-09 Day         1000          1        100
01-FEB-09 01-FEB-09 Day         1000          1        100
02-FEB-09 02-FEB-09 Day         1000          1        100
PER_STRT  PER_END   PER_D      EMPID      COMBO      SALES
28-FEB-09 28-FEB-09 Day         1000          1        100
01-DEC-08 31-DEC-08 Month       1000          1       1000
01-JAN-09 31-JAN-09 Month       1000          1       1000
01-FEB-09 28-FEB-09 Month       1000          1       1000
01-DEC-08 01-DEC-08 Day         1000          2        200
02-DEC-08 02-DEC-08 Day         1000          2        200
31-DEC-08 31-DEC-08 Day         1000          2        200
01-JAN-09 01-JAN-09 Day         1000          2        200
02-JAN-09 02-JAN-09 Day         1000          2        200
31-JAN-09 31-JAN-09 Day         1000          2        200
01-FEB-09 01-FEB-09 Day         1000          2        200
PER_STRT  PER_END   PER_D      EMPID      COMBO      SALES
02-FEB-09 02-FEB-09 Day         1000          2        200
28-FEB-09 28-FEB-09 Day         1000          2        200
01-DEC-08 31-DEC-08 Month       1000          2       2000
01-JAN-09 31-JAN-09 Month       1000          2       2000
01-FEB-09 28-FEB-09 Month       1000          2       2000
27 rows selected.
SQL> select *
  2  from  T
  3  model
  4  return updated rows
  5  partition by (empid,combo,case when per_desc='Day' then   TO_char(per_strt+1,'iw')  else '99' e
nd as  pp, case when  to_char(PER_STRT,'mm')='12' and  TO_char(per_strt+1,'iw')='01'  then extract(
year from PER_STRT) +1 else extract( year from PER_STRT)  end   yy )
  6  dimension by(row_number()over(partition by empid,combo,case when per_desc='Day' then   TO_char(
per_strt+1,'iw') else '99' end  order by PER_STRT) rn)
  7  measures(PER_STRT, PER_END,PER_Desc, sales somme)ignore nav
  8  rules
  9  upsert
10  iterate(100)
11  until(presentv(PER_STRT[iteration_number+2],1,0)=0)
12  ( somme[0]=somme[0]+somme[iteration_number+1],
13   PER_Desc[0]=case when PER_Desc[iteration_number+1] ='Day'  then 'Week' else 'Year'  end ,
14  PER_STRT[0]=min(PER_STRT)[any],
15  PER_end[0]=max(PER_end)[any]  )
16  order by empid,combo,PER_Desc,per_strt;
     EMPID      COMBO PP         YY         RN PER_STRT  PER_END   PER_D      SOMME
      1000          1 49       2008          0 01-DEC-08 02-DEC-08 Week         200
      1000          1 01       2009          0 28-DEC-08 02-JAN-09 Week         850
      1000          1 05       2009          0 30-JAN-09 31-JAN-09 Week         600
      1000          1 06       2009          0 01-FEB-09 02-FEB-09 Week         200
      1000          1 09       2009          0 28-FEB-09 28-FEB-09 Week         100
      1000          1 99       2008          0 01-DEC-08 31-DEC-08 Year        1000
      1000          1 99       2009          0 01-JAN-09 28-FEB-09 Year        2000
      1000          2 49       2008          0 01-DEC-08 02-DEC-08 Week         400
      1000          2 01       2009          0 31-DEC-08 02-JAN-09 Week         600
      1000          2 05       2009          0 31-JAN-09 31-JAN-09 Week         200
      1000          2 06       2009          0 01-FEB-09 02-FEB-09 Week         400
     EMPID      COMBO PP         YY         RN PER_STRT  PER_END   PER_D      SOMME
      1000          2 09       2009          0 28-FEB-09 28-FEB-09 Week         200
      1000          2 99       2008          0 01-DEC-08 31-DEC-08 Year        2000
      1000          2 99       2009          0 01-JAN-09 28-FEB-09 Year        4000
14 rows selected.
SQL> Regards
Salim.

Similar Messages

  • GROUP BY GROUPING SETS Clarification of Format

    Hello.
    I am trying to validate the answers to 2 questions I have listed below.
    Would it be possible for someone to assist me with clarifying these 2 questions and answer statements? Please clarify the portion of the answer that is in
    Bold Text and Italicized. Why is one answer enclosed in brackets and the other not?
    Basically I need to figure out how to determine the syntax of these parenthesis and why they differ from each question. Is it a format issue or is it based on how the question is asked.
    Question #1-
    You are a developer for a Microsoft SQL Server 2008 R2 database instance used to support a customer service application. 
    You create tables named complaint, customer, and product as follows: 
    CREATE TABLE [dbo].[complaint] ([ComplaintID] [int], [ProductID] [int], [CustomerID] [int], [ComplaintDate] [datetime]); 
    CREATE TABLE [dbo].[customer] ([CustomerID] [int], [CustomerName] [varchar](100), [Address] [varchar](200), [City] [varchar](100), [State] [varchar](50), [ZipCode] [varchar](5)); 
    CREATE TABLE [dbo].[product] ([ProductID] [int], [ProductName] [varchar](100), [SalePrice] [money], [ManufacturerName] [varchar](100)); 
    You need to write a query to sum the sales made to each customer who has made a complaint by the following entries:
    ·Each customer name
    ·Each product name
    ·The grand total of all sales 
    Which SQL query should you use?
    SELECT c.CustomerName, p.ProductName, SUM(p.SalePrice) AS Sales
    FROM product p 
    INNER JOIN complaint com ON p.ProductID = com.ProductID 
    INNER JOIN customer c ON com.CustomerID = c.CustomerID
    GROUP BY GROUPING SETS ((c.CustomerName), (p.ProductName), ());
    Question #2 - 
    You are a developer for a Microsoft SQL Server 2008 R2 database instance. 
    You create tables named order, customer, and product as follows: 
    CREATE TABLE [dbo].[order] ([OrderID] [int], [ProductID] [int], [CustomerID] [int],[OrderDate] [datetime]); 
    CREATE TABLE [dbo].[customer] ([CustomerID] [int], [CustomerName] [varchar](100),[Address] [varchar](200), [City] [varchar](100), [State] [varchar](50),
    [ZipCode] [varchar](5)); 
    CREATE TABLE [dbo].[product] ([ProductID] [int], [ProductName] [varchar](100), [SalePrice] [money], [ManufacturerName] [varchar](100)); 
    You need to write a query to sum the sales made to each customer by the following entries:
    ·The Customer name and product name
    ·The grand total of all sales
     Which SQL query should you use?
    SELECT c.CustomerName,p.ProductName,SUM(p.SalePrice) AS Sales
    FROM product p 
    INNER JOIN [order] o ON p.ProductID = o.ProductID 
    INNER JOIN customer c ON o.CustomerID = CustomerID
    GROUP BY GROUPING SETS ((c.CustomerName, p.ProductName), ());
    Your help would be highly appreciated. :)
    Thanks

    Its just to identify the GROUPING SET.When you enclose, the grouping would take for the combination.
    Ok, it would be better to see with an example as below:
    create table T1 (Col1 Varchar(100),Col2 int,Col3 int)
    Insert into T1 Select 'SQL',10,100
    Insert into T1 Select 'SQL',11,100
    Insert into T1 Select 'Oracle',20,500
    SELECT p.col1,p.col2,SUM(p.col3) AS Sales
    FROM T1 p
    GROUP BY GROUPING SETS ((p.Col1,p.Col2), ());/*Oracle 20 500
    SQL 10 100
    SQL 11 100
    NULL NULL 700*/
    SELECT p.col1,p.col2,SUM(p.col3) AS Sales
    FROM T1 p
    GROUP BY GROUPING SETS ((p.Col1),(p.Col2), ());
    /*NULL 10 100
    NULL 11 100
    NULL 20 500
    NULL NULL 700
    Oracle NULL 500
    SQL NULL 200*/
    Drop table T1

  • GROUP BY GROUPING SETS for a selected month and for year to date

    Below is a code example to demonstrate this question:
    declare @test table (ID int, Quantity int, Day date);
    insert into @test values
    (4, 500, '1/18/2014'),
    (4, 550, '1/28/2014'),
    (7, 600, '1/10/2014'),
    (7, 750, '1/11/2014'),
    (7, 800, '1/20/2014'),
    (1, 100, '1/2/2014'),
    (1, 125, '1/10/2014'),
    (8, 300, '1/7/2014'),
    (9, 200, '1/17/2014'),
    (9, 100, '1/22/2014'),
    (4, 900, '2/18/2014'),
    (4, 550, '2/28/2014'),
    (7, 600, '2/10/2014'),
    (7, 700, '2/11/2014'),
    (7, 800, '2/20/2014'),
    (1, 100, '2/2/2014'),
    (1, 150, '2/10/2014'),
    (8, 300, '2/7/2014'),
    (9, 200, '2/17/2014'),
    (9, 100, '2/22/2014'),
    (4, 500, '3/18/2014'),
    (4, 550, '3/28/2014'),
    (7, 600, '3/10/2014'),
    (7, 750, '3/11/2014'),
    (7, 800, '3/20/2014'),
    (1, 100, '3/2/2014'),
    (1, 325, '3/10/2014'),
    (8, 300, '3/7/2014'),
    (9, 200, '3/17/2014'),
    (9, 100, '3/22/2014'),
    (4, 500, '4/18/2014'),
    (4, 550, '4/28/2014'),
    (7, 100, '4/10/2014'),
    (7, 750, '4/11/2014'),
    (7, 800, '4/20/2014'),
    (1, 100, '4/2/2014'),
    (1, 325, '4/10/2014'),
    (8, 300, '4/7/2014'),
    (9, 200, '4/17/2014'),
    (9, 100, '4/22/2014'),
    (4, 500, '5/18/2014'),
    (4, 550, '5/28/2014'),
    (7, 600, '5/10/2014'),
    (7, 750, '5/11/2014'),
    (7, 50, '5/20/2014'),
    (1, 100, '5/2/2014'),
    (1, 325, '5/10/2014'),
    (8, 300, '5/7/2014'),
    (9, 200, '5/17/2014'),
    (9, 100, '5/22/2014');
    --detail
    select *
    from @test;
    --aggregation
    select
    TotalQuantity = sum(Quantity),
    [Month] = month(Day)
    from @test
    group by
    grouping sets
    (month(Day)),
    (year(Day))
    go
    This is the aggregation query result:
    However, the desired result is to return only two rows: one row for month 3 and the other row for year to date (in the picture above YTD is the row that appears with {null} in the Month column).  Is there a way to achieve this goal by modifying the
    sample code above?  The requirement is to only read the data once (do not want a solution that involves a UNION which implies reading the data twice).

    you can add required filters in having clause. Here is the query -
    select
    TotalQuantity = sum(Quantity),
    [Month] = month(Day)
    from @test
    group by
    grouping sets
    (month(Day)),
    (year(Day))
    having
    month(Day) = 3 or month(Day) is null;

  • Question about email setting: how  do i change the setting so i need to login to check my email. Currently it automatically come to the inbox without the need to log in. Thanks

    Question about email setting: how  do i change the setting so i need to login to check my email. Currently it automatically come to the inbox without the need to log in.

    You don't. Email comes in either by push or when you invoke the email app. Ther is no password except when you first set up the account. If your iPad is not being used as your personal device and you need to shield emails from other users, then don't use the email app.  Instead, use web mail if available from your provider.

  • Is this a bug with grouping sets?

    Version is Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    SQL> with data as
      2  (select rownum r, 'X' x, 1 n from dual connect by rownum <= 10)
      3  select x
      4       , sum(n) s
      5       , (select sum(1) from dual where dummy = x) t
      6  from data
      7  group by grouping sets (x, ())
      8  /
    X          S          T
    X         10          1
              10
    SQL>  Shouldn't the superaggregate row have a 1 in the T column?

    Here's your QUERY with the addition of the GROUPING() function:
    SQL> WITH data AS
      2  (
      3     SELECT rownum r
      4          , 'X'    x
      5          , 1      n
      6     FROM   dual
      7     CONNECT BY rownum <= 10
      8  )
      9  SELECT GROUPING(x)
    10       , x
    11       , sum(n) s
    12       , (SELECT sum(1) FROM dual WHERE dummy = x) t
    13  FROM   data
    14  GROUP BY GROUPING SETS (x, ())
    15  ;
    GROUPING(X) X          S          T
              0 X         10          1
              1           10In this case the value for X is null because it's a subtotal row. If you look at the execution plan for this statement:
    PLAN_TABLE_OUTPUT
    SQL_ID  gumphwvgumqc4, child number 0
    WITH data AS (  SELECT rownum r       , 'X'    x       , 1      n  FROM
      dual  CONNECT BY rownum <= 10 ) SELECT /*+gather_plan_statistics*/ x
        , sum(n) s      , (SELECT sum(1) FROM dual WHERE dummy = x) t FROM
    data GROUP BY GROUPING SETS (x, ())
    Plan hash value: 1718326399
    | Id  | Operation                       | Name | Starts | E-Rows | A-Rows |   A-Time   | Buffers |  OMem |  1Mem | Used-Mem |
    |   0 | SELECT STATEMENT                |      |      1 |        |      2 |00:00:00.01 |       0 |    |  |          |
    |   1 |  SORT AGGREGATE                 |      |      2 |      1 |      2 |00:00:00.01 |       4 |    |  |          |
    |*  2 |   TABLE ACCESS FULL             | DUAL |      2 |      1 |      1 |00:00:00.01 |       4 |    |  |          |
    |   3 |  SORT GROUP BY ROLLUP           |      |      1 |      1 |      2 |00:00:00.01 |       0 |  2048 |  2048 | 2048  (0)|
    |   4 |   VIEW                          |      |      1 |      1 |     10 |00:00:00.01 |       0 |    |  |          |
    |   5 |    COUNT                        |      |      1 |        |     10 |00:00:00.01 |       0 |    |  |          |
    |   6 |     CONNECT BY WITHOUT FILTERING|      |      1 |        |     10 |00:00:00.01 |       0 |    |  |          |
    |   7 |      FAST DUAL                  |      |      1 |      1 |      1 |00:00:00.01 |       0 |    |  |          |
    Predicate Information (identified by operation id):
       2 - filter("DUMMY"=:B1)The value for X is being bound to the subquery. If X is null this won't return any rows (I'm sure you knew that :) ). I would say this is expected albeit confusing behavior. You get the same results if you use CUBE or ROLLUP as well.

  • Isse with using Grouping Sets in SQL Server 2008 R2

    Hi,
    I created a query in SQL Server 2012 using grouping sets that works fine.  When I try to use the same query in SQL Server 2008 I get an error ("Inccorrect syntax near SETS").
    I researched using grouping sets in 2008 and didn't see any issue with my query.  What is different in grouping sets 2008 vs 2012?
    SELECT tl.ClientRegionCd as [Client Region Code] , tl.ClientRegionDesc as [Region Name], count(tl.CompleteICN) as [Trauma Letters Sent]
    from TORT_Trauma_Letters tl
    Where CONVERT(VARCHAR(26), tl.SecondNoticeSent, 23) between '2014-06-12' and '2014-06-12'
    GROUP BY GROUPING SETS((tl.ClientRegionCd, tl.ClientRegionDesc), ())
    Stacie

    Check this blog post as how to deal with date ranges
    http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/16/bad-habits-to-kick-mishandling-date-range-queries.aspx
    For your result you can simply achieve your result with UNION ALL, e.g.
    select Client, Region, Letters
    from myTable 
    UNION ALL
    select NULL, NULL, SUM(letters) as Letters
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • HT5312 I have never set up any security questions and now it is asking me for one.... how do you answer a question you never set up?????

    I have never set up a security quesiton and now it is asking me for one... i have set up 40 ipads so far without personal security info... how am i to respond to a security question i never set up????!

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • OrgChart - Group setting not respected when default hierarchy clicked

    Does anyone else get this problem in OrgChart (staged)?
    If a group is defined and set to u201CGroupu201D via the settings panel by the end user, then clicking the default root icon then the resulting hierarchy starts at the default root but without members grouped. 
    If the settings panel is opened, the group setting is still u201CGroupu201D (as expected).  Simply clicking u201CApply settingsu201D does result in the members being grouped.
    Looks like a bug to me, anyone else able to replicate?

    Hey Stephen,
    This funcitonality should work as expected.
    First, please verify that youset up groups from the admin first? If not, you should do it before doing anything from settings.
    From the setting when you select u201CGroupu201D u2013 you will see the grouping, the nodes will be grouped; when you select u201CShow Group Membersu201D u2013 the group will be expanded; when you select u201CHide Group Membersu201D u2013 the box with this group will disappear from the OrgChart.
    Once this is setup, if you are still experiencing issues, verify the CDS log, as it may be a permissions issue (ie no write or modify access for user settings).
    Hope this helps
    Carl

  • My icloud email address is included in a friend's address group set up in Gmail.  When they send an email to the group, the email never gets through to my icloud address - why?

    My icloud email address is included in a friend's address group set up in Gmail.  When they send an email to the group, the email never gets through to my icloud address - why?

    They've always been able to send to me individually - just not when my email is part of a group or even when it's just included with several other addresses added one at a time.

  • How to sort specific column when using GROUPING SETS in SQL Server?

    If I remember correctly, in SQL Server, it is not recommended to use "ORDER BY" when there's already a GROUP BY GROUPING SETS.
    I have two columns: [UPC#] & [Description] both are varchar.
    My grouping sets is like this:
    GROUP BY
    GROUPING SETS
    ([UPC],[Description])
    I don't have 'ORDER BY' but it's automatically sorting the Description column.
    If I added a 3rd column, sum(Qty), then it doesn't sort by Description anymore. But if I added
    ORDER BY [Description]
    then the grand total of sum(Qty) will be at the first row instead of the last.
    Is there a way to sort the Description column and still let the grand total of sum(Qty) be at the last row instead?
    Thanks.

    Yes, it works.
    Thank you.
    Could you kindly explain the logic?
    I don't quite understand the "= 3 THEN 1 ELSE 0" part.
    Is the #3 mean the column index 3?
    GROUPING_ID returns a bit mask value depending on number of columns grouped in the result 
    So when you do GROUPING_ID(([UPC]),([Description]))
    it has two columns UPC and Description so bit mask will be as follows
    0 ie 00 for rows grouped by both UPC and Description fields
    1 ie 01 for rows grouped by UPC ie UPC subtotals
    2 ie 10 for rows grouped by Description ie Description subtotals
    3 ie 11 for rows not grouped by both columns ie Grand total
    see
    http://msdn.microsoft.com/en-IN/library/bb510624.aspx
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • Group by Grouping sets in obiee11g query

    Hi Experts
    I have few unbalanced heirarchies in the rpd. I have created level beased heirarchy for those ragged and skipped hierarchy but while generating the report using those hierarchy generates a huge SQL involving 20-30 UNION ALLs . Instead it should have generated comparatively smaller query using Group by Grouping Sets but it is not.
    I have also tried enabling this parameter in DB properties in OBIEE11g ( changed the default DB from 9i to 11g in obiapps 7.9.6.3 rpd) but still no use .
    As a result of huge query geenration the performance is badly impacted.
    Any thought on this pls.

    I have run into the same problem. Any hints about what might be the reason or, even better, how to address it, will be more than welcome.
    thanks in advance

  • GROUP BY grouping sets

    Hello everybody,
    I have this query
    SELECT ALL
                M_PAGAMENTO||' '||D_TIPO MPAGA,
                grouping(F.KIND_F),
                DECODE (grouping(F.KIND_F), 0 , 'Totali IVA',F.KIND_F)  a1,
                 case
                 when grouping(F.KIND_F) = 1 then F.KIND_F
                 when grouping(F.KIND_F) = 0 then 'Totali IVA'
                 end  TIPOF,
               F.KIND_F  TIPOF,
               COUNT(*) NFATTURE,
                sum(F.TOT_FT) TFATTURA, sum(F.BOLLO) TBOLLO,
                K_IVA, SUM(FA.IPBFA) TIMP, SUM(FA.IPSFA) TIPS
    FROM A_FATTURE  F,A_PAZIENTI A,TIPOLOGIA_PAGAMENTI p  ,A_FATTURE_ALIQUOTE FA
    where (F.TIPORD = A.TIPORD AND F.K_CODE = A.K_CODE  AND F.ANNO = A.ANNO)
    AND   (FA.TIPORD = F.TIPORD AND FA.K_CODE = F.K_CODE AND FA.ANNO = F.ANNO AND FA.N_FATT_D = F.N_FATT_D)
    and p.ID_TIPO = f.M_PAGAMENTO
    &MYWHERE
    GROUP BY grouping sets (M_PAGAMENTO||' '||D_TIPO,F.KIND_F),K_IVA
    ORDER by  1
    Why I get this result(A1, tipof) = NULL but they would be = 'D' (F.KIND_F ='D'
    MPAGA                    GROUPING(F.KIND_F)     A1     TIPOF     TIPOF     NFATTURE     TFATTURA     TBOLL      K_IVA     TIMP          TIPS
    01 Contante               1                              5          3183,24          7,24     20     250          50
    01 Contante               1                              3          2342,43          5,43     FC     5,43          0
    01 Contante               1                              50          7024,61          9,91     ES     24458,91     0
    02 Assegno               1                              1          780,81          1,81     FC     1,81          0
    02 Assegno               1                              2          816,96          1,81     ES     755,15          0
    02 Assegno               1                              1          780,81          1,81     20     50          10
    04 Carta di credito          1                              1          780,81          1,81     FC     1,81          0
    04 Carta di credito          1                              1          780,81          1,81     20     50          10
    04 Carta di credito          1                              1          780,81          1,81     ES     719          0
                        0     Totali IVA     Totali IVA     D     53          8622,37          23,53     ES     25933,06     0
                        0     Totali IVA     Totali IVA     D     5          3904,05          9,05     FC     9,05          0
                        0     Totali IVA     Totali IVA     D     7          4744,86          10,86     20     350          70where I am wrong?
    thanks for any help

    Rosario,
    Those rows where grouping(f.kind_f) = 1 are superaggregate rows where you are grouping by M_PAGAMENTO||' '||D_TIPO,K_IVA. So f.kind_f doesn't come into play for these rows, and it shows a null value.
    You can of course hard code a 'D' value in there, but values of the f.kind_f column are always null at this grouping level.
    See this example:
    SQL> select deptno
      2       , job
      3       , extract(year from hiredate)
      4       , sum(sal)
      5       , grouping(job)
      6    from emp
      7   group by deptno
      8       , grouping sets (job,extract(year from hiredate))
      9  /
        DEPTNO JOB       EXTRACT(YEARFROMHIREDATE)   SUM(SAL) GROUPING(JOB)
            10 CLERK                                     1300             0
            10 MANAGER                                   2450             0
            10 PRESIDENT                                 5000             0
            20 CLERK                                     1900             0
            20 ANALYST                                   6000             0
            20 MANAGER                                   2975             0
            30 CLERK                                      950             0
            30 MANAGER                                   2850             0
            30 SALESMAN                                  5600             0
            10                                1981       7450             1
            10                                1982       1300             1
            20                                1980        800             1
            20                                1981       5975             1
            20                                1982       3000             1
            20                                1983       1100             1
            30                                1981       9400             1
    16 rijen zijn geselecteerd.
    SQL> select deptno
      2       , job
      3       , extract(year from hiredate)
      4       , sum(sal)
      5       , grouping(job)
      6       , decode(grouping(job),1,job)
      7    from emp
      8   group by deptno
      9       , grouping sets (job,extract(year from hiredate))
    10  /
        DEPTNO JOB       EXTRACT(YEARFROMHIREDATE)   SUM(SAL) GROUPING(JOB) DECODE(GR
            10 CLERK                                     1300             0
            10 MANAGER                                   2450             0
            10 PRESIDENT                                 5000             0
            20 CLERK                                     1900             0
            20 ANALYST                                   6000             0
            20 MANAGER                                   2975             0
            30 CLERK                                      950             0
            30 MANAGER                                   2850             0
            30 SALESMAN                                  5600             0
            10                                1981       7450             1
            10                                1982       1300             1
            20                                1980        800             1
            20                                1981       5975             1
            20                                1982       3000             1
            20                                1983       1100             1
            30                                1981       9400             1
    16 rijen zijn geselecteerd.Regards,
    Rob.

  • Has anyone used grouping sets or perhaps rollup function

    I am trying to do a rollup query ....to sum up sales based on an
    account number you would think pretty simple.....so here is the
    query I wrote
    SELECT broker_number
    account_number , ACCOUNT_NAME ,
    to_char( SUM ( FACTORY_NET_AMT ) , '9,999,999,999') sales$
    FROM broker_account_expanded
    WHERE product_level = 'BRND'
    and product_level_Code not in ( select PROD_CATEGORY_CD from
    genesis.tFIN_BRAND )
    AND PRODUCT_LEVEL_CODE = '100515'
    group by GROUPING SETS (
    ( broker_number , account_number , account_name ))
    however I am getting the following error
    SQL> /
    group by GROUPING SETS (
    ERROR at line 9:
    ORA-00933: SQL command not properly ended
    Any ideas ?
    Thank's
    Sameer Handa

    I think correct would be:
    GROUP BY ROLLUP (broker_number , account_number , account_name )

  • Why is DPM 2012 R2 splitting this Co-located Protection Group Set across three different tapes?

    I have 10 protection groups that ran Saturday night.  I have put information about them in the following table:
    I extracted the data in the table using Get-DPMProtectionGroup CmdLet and the job information from the Monitoring page of the DPM admin console.  As you can see from the tape barcode, DPM wrote the first four PGs to one tape, then started a second
    tape, and finally failed when starting a third because it had run out of free tapes.
    All of the protection groups are assigned to the same "Co-Located Protection Group Set" in the "Tape Optimization Setup" dialog box.
    Prior to the jobs running, I painstakingly ensured that each of the Protection Group's "Select Long-Term Goals" and "Select Library and Tape Details" screens are identical as follows:
    Prior to running the jobs I had already disabled autoclean on the tape library.
    I have checked to see if the tape drive is reporting IO error 0x8007045D using the method described in this blog post:
    http://blogs.technet.com/b/dpm/archive/2012/05/14/things-you-can-do-to-help-data-protection-manager-utilize-your-tapes-full-capacity.aspx
    There seems to be no mention of 0x8007045D or -2147023779 in any of the MSDPM*.Errlog files.
    These are LTO6 tapes with a capacity of 2.5 TB each.  The total data for all the jobs put together is less than 300GB.
    Why is DPM 2012 R2 splitting these protection groups across three different tapes? 
    What else should I check for that might cause DPM to start a new tape?

    Hi Mike,
    Thanks for taking a look at the logs.  I just wanted to point out that there were actually two changes made just before collocation succeeded:
    Write Period and Expiry Tolerance were increase
    Full Verbose logging was enabled
    This technet article states that Full Verbose logging affects performance.  If the problem with collocation is caused by a race condition then it is
    possible that enabling logging actually caused collocation to succeed. At this point there doesn’t seem to be any evidence pointing to which of the two changes resulted in collocation succeeding.
    I propose I run the following tests to differentiate the two:
    Test #1 - Collocation Confirmation
    Repeat last weekend's test to confirm that successful collocation wasn't an anomaly.  Configuration:
    full verbose logging: Enabled
    Expiry Tolerance: 1 year
    Write Period: 1 year
    Test #2 - Logging Only
    Test to see whether enabling Full Verbose logging enabled collocation to succeed.  Configuration:
    full verbose logging: Enabled
    Expiry Tolerance: 7 days
    Write Period: 6 day
    Thanks for your help,
    Alex

  • Grouping set

    What is the difference between grouping sets and grouping. Can any one explain to me in easy way. I will be appreciate. Thanks.

    i guess u are aware of this thread on grouping sets and grouping :-)
    http://orafaq.com/node/56
    http://www.psoug.org/reference/rollup.html

Maybe you are looking for

  • Sign into icloud box won't go away

    As soon as I power on my ipad mini, the sign into iCloud dialogue box pops up.  I type in the password, but it pops up with the box again as if I didn't type anything in.   I've tried holding the home and power buttons simultaneously to restart it, t

  • WF in BSP

    Hello In the event OnInputProcessing of the page Main.htm of the BSP application ROS_SELF_REG we sent questionnaires to the supplier by the FM ROS_QSTN_DETECT_AND_SEND after the execution of this function we need to trigger a workflow and i'm thinkin

  • Export getting cancelled

    Hi all, Im working in  ECC 6.0 system. While transporting the development request to Quality server using Transport of copies, the export  gets cancelled. The target system is configured as dummy. I did the following things :- 1. Checked the transpor

  • FB3 M3 Beta2- Advanceddatagrid column header multiple sort

    Hello People, Before 10-1 when the M3 B2 of FB3 comes out i had normal columnheaders with the new beta version there are suddenly multi sort functions added to the columnheaders of the advanced datagrid! How can i remove those.. i have alot of column

  • Reminder: Please use GroupSpace for Tech Preview feedback

    We recently announced the availability of the live WebLogic Portal GroupSpace community for Tech Preview 2. GroupSpace is one of the highlights of the 9.x release, and you can now use it to log and discuss Tech Preview-related issues, store documents