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
0 answers

Why is Rollup not treeshaking my library?

I have written an es6 library that compiles to produce the following: // All the library code, then... export { default as Campaign } from './modules/campaign.js'; export { default as Triggers } from './modules/triggers.js'; export { default as…
punkrockbuddyholly
  • 9,675
  • 7
  • 36
  • 69
0
votes
1 answer

rollup, coffeescript issue when i dont use coffescript

Trying to add rollup to my babel codebase. I'm getting an error related to coffee script when my code has no coffee script. I'm new to rollup so any help would be appreciated Seems to be a library called config but I have no idea what might be…
Terence Chow
  • 10,755
  • 24
  • 78
  • 141
0
votes
1 answer

When using MYSQL GROUP BY WITH ROLLUP on Year(date) and Month(date) i am not able to change Null to 'Total'

I want to create a table using GROUP BY WITH ROLLUP and get total rows instead of null. $sql ="SELECT IF(YEAR(transaktioner.datum) is null or YEAR(transaktioner.datum) = '','Total',YEAR(transaktioner.datum)) as Year, …
John
  • 55
  • 5
0
votes
1 answer

Angular ng-packagr Rollup Build Error

I have looked at every issue I can find that has a reference to the error I'm having when trying to package my Angular component library. The error is: BUILD ERROR Cannot call a namespace ('moment') Error: Cannot call a namespace ('moment') ...…
pjlamb12
  • 2,300
  • 2
  • 32
  • 64
0
votes
1 answer

Rollup with CommonJS, import and exports with treeshaking

I'm trying to get rollup, commonjs, es6 and tree shaking working correctly. Currently, I have the following build script: 'use strict'; const rollup = require('rollup'); const resolve = require('rollup-plugin-node-resolve'); const commonjs =…
Prisoner
  • 27,391
  • 11
  • 73
  • 102
0
votes
0 answers

ROLLUP function in SQL

In my line of work, rollup refers to combining/averaging months or quarters. In this case, the rollup is based on INDCODE and PERIOD. I have a table named INDUSTRY that contains data from quarters 1, 2, 3, and 4. Below is a sample of what it looks…
Tim Wilcox
  • 1,275
  • 2
  • 19
  • 43
0
votes
1 answer

How to use redux-form in peer dependency

I am trying to create a ES6 module of a login form using rollup and react-redud. I have a rollup with the following configuration: const plugins = [ // Unlike Webpack and Browserify, Rollup doesn't automatically shim Node // builtins like…
Dimitri Kopriwa
  • 13,139
  • 27
  • 98
  • 204
0
votes
1 answer

Rollup function and percentage value in total

I tried to display tablespace usage by using a ROLLUP function and the result looks good. However, as you can see, percent_free of a Total is just a sum instead of Percentage. Can you help me to change the below query to get a percent value of a…
Sigularity
  • 917
  • 2
  • 12
  • 28
0
votes
3 answers

Mysql Rollup with multiple group

Mytable with Id as autoincrement Customer, Date and Amount I want to make a rollup that will sum the amount of every customer every day I mean that the rollup is grouped by Date and Customer This is what should my result look like…
Yahia Baiba
  • 136
  • 10
0
votes
1 answer

SCORM 2004 Rollup with single sco

I'm having issues rolling up a completion from a completed item. I'm running this on SABA and I can successfully set the completion_status and success_status on the item but having issues rolling it up to the next level on the LMS, both satisfied…
blewis
  • 1
0
votes
3 answers

How do I do a ROLLUP on Language column and get a row of TOTAL as the last row?

I want to do a ROLLUP on the Language column and generate the last row as a Total. I am not sure where to put the ROLLUP. For Eg: AS BEGIN declare @sqlCommand NVARCHAR(4000) = 'SELECT Language, col2, col3, col4, Total…
Jeet Patel
  • 41
  • 9
0
votes
1 answer

t-sql need a rollup view from hierarchal data

I have an sql-server 2012 table that looks like this: lvl | keywords -----|------------ A | null A1 | null A1.1 | red, green A1.2 | blue A1.3 | orange, yellow A2 | null A2.1 | brown A2.2 | black, purple B | null B1 | null B1.1 |…
emphyrio
  • 87
  • 7
0
votes
0 answers

Angular2 compiler turns module 'x' into 'x/index'

I'm having a hard time to understand why @angular compiler changes my modules names: directive.ts import isNil from 'lodash-es/isNil'; ... @Directive({ selector: '[aColor]', }) export class AColorDirective { } tsconfig.aot.json { …
PRAISER
  • 793
  • 7
  • 15
0
votes
0 answers

How to use preact-compat with server side rendering in rollup + buble setup?

I have a preact app which is using rollup + buble. I need to use another component text-mask which uses React. I am trying to create alias within my rollup build file. For the client side, it works flawlessly however when building on the server…
Ranjith Nair
  • 475
  • 1
  • 6
  • 17
0
votes
1 answer

Ngx\clipboard Not working with Aot and Rollup

I have tried to implement aot in my app but While building my app with aot and rollup gets this error.I have used ngx-clipboard. 'ngx-clipboard/src/index' is imported by wwwroot\app\aot\app\app.module.ngfactory.js, but could not be resolved ΓÇô …
user3505487
  • 95
  • 2
  • 6