Questions tagged [rollup]

The ROLLUP operator is useful in generating reports that contain subtotals and totals. The ROLLUP operator generates a result set that is similar to the result sets generated by the CUBE operator

The ROLLUP operator is useful in generating reports that contain subtotals and totals. The ROLLUP operator generates a result set that is similar to the result sets generated by the CUBE operator. For more information, see Summarizing Data Using CUBE.

Following are the specific differences between CUBE and ROLLUP:

  • CUBE generates a result set that shows aggregates for all combinations of values in the selected columns.
  • ROLLUP generates a result set that shows aggregates for a hierarchy of values in the selected columns.

For example, a simple table Inventory contains the following:

Item                 Color                Quantity                   
-------------------- -------------------- -------------------------- 
Table                Blue                 124                        
Table                Red                  223                        
Chair                Blue                 101                        
Chair                Red                  210 

The next query

SELECT CASE WHEN (GROUPING(Item) = 1) THEN 'ALL'
            ELSE ISNULL(Item, 'UNKNOWN')
       END AS Item,
       CASE WHEN (GROUPING(Color) = 1) THEN 'ALL'
            ELSE ISNULL(Color, 'UNKNOWN')
       END AS Color,
       SUM(Quantity) AS QtySum
FROM Inventory
GROUP BY Item, Color WITH ROLLUP 

generates the following subtotal report:

Item                 Color                QtySum                     
-------------------- -------------------- -------------------------- 
Chair                Blue                 101.00                     
Chair                Red                  210.00                     
Chair                ALL                  311.00                     
Table                Blue                 124.00                     
Table                Red                  223.00                     
Table                ALL                  347.00                     
ALL                  ALL                  658.00   

If the ROLLUP keyword in the query is changed to CUBE, the CUBE result set is the same, except these two additional rows are returned at the end:

ALL                  Blue                 225.00                     
ALL                  Red                  433.00  

The CUBE operation generated rows for possible combinations of values from both Item and Color. For example, not only does CUBE report all possible combinations of Color values combined with the Item value Chair (Red, Blue, and Red + Blue), it also reports all possible combinations of Item values combined with the Color value Red (Chair, Table, and Chair + Table).

For each value in the columns on the right in the GROUP BY clause, the ROLLUP operation does not report all possible combinations of values from the column, or columns, on the left. For example, ROLLUP does not report all the possible combinations of Item values for each Color value.

The result set of a ROLLUP operation has functionality similar to that returned by a COMPUTE BY. However, ROLLUP has the following advantages:

  • ROLLUP returns a single result set while COMPUTE BY returns multiple result sets that increase the complexity of application code.
  • ROLLUP can be used in a server cursor while COMPUTE BY cannot.
  • The query optimizer can sometimes generate more efficient execution plans for ROLLUP than it can for COMPUTE BY.
1420 questions
0
votes
1 answer

Adding a pivot to a rollup

I have the following query that gives me aggregated data that I would like to pivot: select provider, title, hd_or_sd, SUM(customer_price), count(distinct title) from `100` group by provider, title, hd_or_sd with rollup I would like to pivot on…
David542
  • 104,438
  • 178
  • 489
  • 842
0
votes
1 answer

How to do a Rollup in SQL Server?

I am trying to complete a Rollup on MS SQL so that my column "DET" has a complete sum at the last row. The Arrive column contains characters so if possible I'm just trying to have the total row in that column be NULL. When I did Group by Date, DET,…
Alex
  • 5
  • 1
  • 3
0
votes
1 answer

ROLLUP returning incorrect value

Stuck on this for a bit today and was wondering can anyone suggest what's going wrong. Here is my code: select g.game_name, r.rental_id, sum(if(datediff(r.return_date, r.due_date) > 0, datediff(r.return_date, r.due_date) * g.overdue_charge_per_day,…
Bake.G
  • 123
  • 1
  • 1
  • 12
0
votes
1 answer

selenium rollup element not found

I am new to selenium ui-element,before this I always choose selenium IDE.When I tried use the rollup command,I define a rollup manager in a uimap.js file: myRollupManager.addRollupRule({ name: 'login_in' , description: 'login' , pre:…
T.Tammy
  • 1
  • 1
0
votes
1 answer

WITH ROLLUP Requiring SUM in Select?

No one was able to help me out with my original question (WITH ROLLUP is only producing NULLs) I have since then found PART of a solution. I trimmed down my query to the following. SELECT wlc.WorkloadCategory ,wl.WorkloadMinutes FROM …
blacksaibot
  • 265
  • 2
  • 12
0
votes
1 answer

Dynamics CRM Plugin - Refresh rollup on delete

I have a specific situation that I need to handle. I have a plugin that refreshes specific rollup field on invoice when invoice detail is created or updated. Now I need to refresh that field when invoice detail is deleted. Analyzing this problem, I…
ddelic
  • 89
  • 13
0
votes
0 answers

RollupJS importing variables from ES6 modules that were never exported

I have an ES6 module with 4 primitive values stored in const variables at the top of my file, along with a default function being exported. This function is imported into main.js and Rollup bundles it into a corresponding dist/js folder. When I look…
jakewies
  • 342
  • 6
  • 18
0
votes
0 answers

GROUP BY with ROLLUP

I have mysql query like this : SELECT branch,ifnull(cluster,'Total --->')AS cluster,COUNT(rs) AS point, (SELECT SUM(rp) from full_mcd where full_mcd.cluster=sefiia_registered_outlet_rs.cluster GROUP BY full_mcd.cluster) …
TheRob
  • 133
  • 2
  • 10
0
votes
1 answer

How to configure RollUp (or Ionic Copy Script) to override files in assets directory on ionic build?

How to configure Ionic App Scripts to update assets on each build? I found: https://github.com/driftyco/ionic-app-scripts#custom-config-files, which says add clean keyword. But it does not update www/assets on build. We need to manually delete this…
Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
0
votes
2 answers

Grunt + rollup + babel config issue

I cannot make rollup transform my ES6 code into ES5. It stays trowing a message Warning: Error transforming main.js with 'babel' plugin: It looks like your Babel configuration specifies a module transformer. Please disable it. If you're using the…
Filipe Merker
  • 2,428
  • 1
  • 25
  • 41
0
votes
0 answers

Rollupjs tree-shaking with typescript decorator modules

When I am using typescript decorators with modules in my script, rollupjs bundles entire modules instead of imported module. main.js import { outter } from './index.js'; let a = new outter(); index.js export * from './display'; export * from…
Yahwe Raj
  • 1,947
  • 5
  • 25
  • 37
0
votes
1 answer

SQL rollup latest non-null column values

I have a SQLAnywhere table like this: id int not null, inserted datetime not null, modified datetime not null, data1 varchar(20) null data2 varchar(20) null The developer didn't put a unique index on the id,…
alacrity
  • 3
  • 2
0
votes
0 answers

Rollup, not tree-shaking properly, providing full bundle

I'm having an issue tree-shaking with rollup. I exported a new function min that does basically nothing from my utils/index.js module. Along with it in that file there are a ton of imports and other exported functions. When I bundle I'm seeing a…
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
0
votes
1 answer

How to rollup columns

We are running SQL Server 2005. I am having problems rolling up columns. create table group_roll ( id_name int, full_name varchar(50), qty int ) go insert into group_roll (id_name, full_name, qty) values (1, 'john smith', 10) insert…
SeyedG
  • 25
  • 1
  • 6
0
votes
1 answer

Cost/Number Rollup In Tree-like structure - Python

I have a database table where each row has: name, child1, child1_quantity, child2, child2_quantity, child3, child3_quantity, price This table will be brought into python as a list of dictionaries or dictionary of dictionaries (doesn't matter). It…
okyere
  • 171
  • 1
  • 3
  • 16