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
78
votes
6 answers

Add a summary row with totals

I know this sounds crazy and probably should not be done this way but I need something like this - I have a records from SELECT [Type], [Total Sales] From Before I want to add an extra row at the end to show the SUM at the end of the table (After).…
user2103670
  • 1,601
  • 10
  • 23
  • 24
57
votes
3 answers

What is the difference between cube, rollup and groupBy operators?

I can't find any detailed documentation regarding the differences. I do notice a difference, because when interchanging cube and groupBy function calls, I get different results. I noticed that for the result using cube, I got a lot of null values on…
Eric Staner
  • 969
  • 2
  • 9
  • 14
44
votes
8 answers

Failed to parse source map

I created an npm library with rollup. Then, I install and use it in a React project. When i npm start the project it throw me this line: Failed to parse source map from…
RandomQuestions
  • 541
  • 1
  • 3
  • 3
44
votes
4 answers

got Can't resolve 'react/jsx-runtime' error while use try to create the shared component with storybook in react-typescript

I tried to create a shared component using a storybook with react-redux. I am using rollup to create a shared component. due to some error unable to create the shared component. package.json { "name": "story1", "version": "0.1.0", "private":…
Gmv
  • 2,008
  • 6
  • 29
  • 46
36
votes
3 answers

When to use GROUPING SETS, CUBE and ROLLUP

I have recently learned about GROUPING SETS, CUBE and ROLLUP for defining multiple grouping sets in sql server. What I am asking is under what circumstances do we use these features ? What are the benefits and advantages of using them? SELECT…
June
  • 974
  • 5
  • 20
  • 34
32
votes
15 answers

Uncaught Error: Cannot find module 'react/jsx-runtime'

I am exploring making a component library using React and rollup. I'm finding that the app that is consuming the library is bundling it in the wrong order. This is causing the below error: bundle.js:99 Uncaught Error: Cannot find module…
Charklewis
  • 4,427
  • 4
  • 31
  • 69
29
votes
7 answers

Does rollup support typescript in rollup config file?

It seems we can use typescript to write rollup config file. Say, I can create a file named rollup.config.ts, with content: import typescript from 'rollup-plugin-typescript2'; export default { input: 'main.ts', plugins: [typescript()], output:…
Freewind
  • 193,756
  • 157
  • 432
  • 708
27
votes
4 answers

How do I add types to a Vite library build?

I followed the vite documentation for using library mode and I am able to produce a working component library. I created the project with the vue-ts preset and in my component I have defined props with their types, and used some interfaces. But…
Neelansh Mathur
  • 516
  • 1
  • 5
  • 10
26
votes
3 answers

Importing from subfolders for a javascript package

I have a typescript library consists of multiple folders. Each folder contains an index.ts file which exports some business logic. I am trying to bundle this with rollup to achieve this behavior on the call site: import { Button, ButtonProps } from…
alioguzhan
  • 7,657
  • 10
  • 46
  • 67
23
votes
1 answer

How to best include assets (images and fonts) referenced in scss files in rollup bundle

I am writing a react component library with typescript, sass and rollup, and I want it to be as standalone as possible. Does anyone have a suggestion on how to best include assets (images and fonts) referenced in scss files? One solution could be…
Mahus
  • 595
  • 1
  • 6
  • 16
23
votes
1 answer

How to embed all dependencies into one fat target bundle with rollup.js?

How do I have to configure rollup.js (=> config file "rollup.config.js") if all dependencies should be embedded into the (fat) result bundle (especially: how to configure the rollup parameters "globals", "external", "plugins.babel.exclude")? Let's…
Natasha
  • 421
  • 1
  • 3
  • 10
23
votes
6 answers

Rollup Error: 'isValidElementType' is not exported by node_modules/react-is/index.js

I'm building a bundle with rollUp using styled-components. My rollup.config.js looks like: import resolve from 'rollup-plugin-node-resolve' import babel from 'rollup-plugin-babel' import commonjs from 'rollup-plugin-commonjs' export default { …
FabioCosta
  • 3,069
  • 6
  • 28
  • 50
23
votes
2 answers

how to include use of node_modules in rollup compile

I repeatedly get this message and I am trying to include the d3.js into my distribution file. Treating 'd3.js' as external dependency I've tried using this plugin import includePaths from 'rollup-plugin-includepaths'; var includePathOptions = { …
user2167582
  • 5,986
  • 13
  • 64
  • 121
23
votes
4 answers

Sum with SQL server RollUP - but only last summary?

I have this query: DECLARE @t TABLE(NAME NVARCHAR(MAX),datee date,val money) insert INTO @t SELECT 'a','2012-01-02',100 insert INTO @t SELECT 'a','2012-01-02',100 insert INTO @t SELECT 'a','2012-01-03',100 insert INTO @t SELECT…
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
22
votes
5 answers

Shared component library best practices

I am creating a shareable React component library. The library contains many components but the end user may only need to use a few of them. When you bundle code with Webpack (or Parcel or Rollup) it creates one single file with all the code. For…
Ollie Williams
  • 1,996
  • 3
  • 25
  • 41
1
2 3
94 95