
The ROLLUP operator is a very useful in generating
reports that contain subtotals and totals which generates a result set that
shows aggregates for a hierarchy of values in the selected columns. The
super-aggregated column is represented by a NULL value and we
can assign any value such as ‘ALL’, although the super-aggregate rows will
always be added last. Multiple aggregates over different columns will be
added if there are multiple GROUP BY columns.
It is useful-
A. By using the ROLLUP option, you can use a single query to generate multiple grouping sets.
B. ROLLUP generates a result set that shows aggregates for a hierarchy of values in the selected columns.
C. By using ROLLUP, you can find total for corresponding to one or more columns
Examples
1. SQL ROLLUP with single column
2. SQL ROLLUP with multiple columns
3. SQL ROLLUP with partial rollup
It is useful-
A. By using the ROLLUP option, you can use a single query to generate multiple grouping sets.
B. ROLLUP generates a result set that shows aggregates for a hierarchy of values in the selected columns.
C. By using ROLLUP, you can find total for corresponding to one or more columns
Examples
1. SQL ROLLUP with single column
2. SQL ROLLUP with multiple columns
3. SQL ROLLUP with partial rollup
WITH ROLLUP, as well as WITH CUBE, both
are non-standard and deprecated.
To understand both operators, we will observe
both the ROLLUP and CUBE operators with the help of a simple example as given
below-
----- Create table variable
DECLARE @Item_List Table
(Product Varchar(20), Maker Varchar(20), Quantity Int)
----- Insert Data into table variable
INSERT INTO @Item_List(Product,Maker, Quantity )
VALUES ('Laptop', 'Dell', 300),
('Laptop', 'Lenovo', 150),
('Laptop', 'HP', 400),
('Desktop', 'Dell', 120),
('Desktop', 'Lenovo', 80),
('Desktop', 'HP', 250)
----- Pull the data from table variable
SELECT * FROM @Item_List;
----- Result by using WITH ROLLUP;
SELECT Product=ISNULL(Product,'ALL'), Maker=ISNULL(Maker,'ALL'), Quantity=Sum(Quantity)
FROM @Item_List
GROUP BY Product, Maker WITH ROLLUP;
|
In addition to the subtotals generated by the ROLLUP extension, the WITH CUBE operator will generate subtotals for all
combinations of the dimensions specified. In general, WITH CUBE
generates a result set that shows aggregates for all combinations of values in
the selected columns.
---- Result by using With Cube
SELECT Product=ISNULL(Product,'ALL'), Maker=ISNULL(Maker,'ALL'), Quantity=Sum(Quantity)
FROM @Item_List
GROUP BY Product , Maker WITH Cube ;
|
As the number of dimensions/columns increase, so
do the combinations of subtotals that need to be calculated. The ROLLUP
operator can also be used to calculate sub-totals for each column, based on the
groupings within that column.
The
Difference between ROLLUP and CUBE
There is only
one major difference between the functionality of the ROLLUP operator and the
CUBE operator. ROLLUP operator generates aggregated results for the selected
columns in a hierarchical way whereas CUBE generates an aggregated result that
contains all the possible combinations for the selected columns or dimensions.
http://www.youtube.com/c/Sql-datatools
Hello,
ReplyDeleteThank you Microsoft Business Intelligence for the post update regularly. KernelTraining is one of the leading DevOps training institutes. Recently i completed my software course in KernelTraining, good Institute where you can get good knowledge by real-time experts. I would strongly recommend KernelTraining. for more details please go through the link: DevOps Training In Hyderabad
Nice...
ReplyDeletebitwise aptitude questions
how to hack flipkart legally
zenq interview questions
count ways to n'th stair(order does not matter)
zeus learning subjective test
ajax success redirect to another page with data
l&t type 2 coordination chart
html rollover image
hack android phone using cmd
how to hack internet speed upto 100mbps
Good...
ReplyDeleteinternships in chennai
winter internship mechanical engineering
internship for aeronautical engineering students in india 2019
kaashiv
list of architectural firms in chennai for internship
paid internships in pune for computer science students
diploma final year project topics for information technology
internship
data science internship report
inplant training
it is good blogs!!!
ReplyDeletepaid internships in pune for computer science students
machine learning training in chennai
data science internship in chennai
dot net training in chennai
kaashiv infotech chennai
internship for aeronautical engineering students in india
internship in automobile industry
big data internship in chennai
machine learning internship in chennai
internship in chennai for it students
nice post.......
ReplyDeleteapache solr resume sample
apache spark sample resume
application developer resume samples
application support engineer resume sample
asp dotnet mvc developer resume
asp net core developer resume
asp net developer resume samples
assistant accountant cv sample
assistant accountant resume
assistant accountant resume sample
branch-operations-manager-resume-samples
ReplyDeletebusiness-executive-resume-samples
business-owner-resume-samples
business-to-business-sales-resume-sample-sales-resumes
cad-design-engineer-resume-samples
call-centre-jobs-resume-sample
ca-resume-samples-chartered-accountant-resume-format
cassandra-database-administrator-resume
category/accountant-resume
category/admin-resume
nice....
ReplyDeletecategory/advocate-resume
category/agriculture-forestry-fishing
category/android-developer-resume
category/assistant-professor-resume
category/chartered-accountant-resume
category/database-resume
category/design-engineer-resume
category/developer-resume
category/engineer-resume
category/entrepreneur-and-financial-services-resume
good..nice..
ReplyDeleteassistant-director-resume-format
assistant-director-resume-sample
assistant-professor-resume-sample
back-office-executive-resume-samples
bank-branch-manager-resume-samples
basketball-coach-resume-sample-coach-resumes
bca-fresher-resume-sample
best-general-manager-resume-example
bpo-resume-freshers-sample
bpo-resume-samples-for-freshers
good ....nice...
ReplyDeleteresume/category/software-testing-resume
resume/category/sslc-resume
resume/category/storekeeper-resume
resume/category/stylist-resume
resume/category/teachers-resume
resume/category/technical-architect-resume
resume/category/web-developer-resume
cics-system-programmer-resume-example
resume/cisco-network-engineer-resume
resume/cisco-network-engineer-resume-sample
good.....nice..
ReplyDeletecategory/maintenance-resume
category/manager-resume
category/mechanical-engineering-resume
category/network-engineer-resume
category/officer-resume
category/operations-resume
category/process-associate-resume
category/quality-control-resumes
category/software-engineer-resume
it is best blogs ....
ReplyDeletecivil-engineer-resume-format
client-service-executive-resume-sample
cognos-developer-resume-samples
college-lecturer-resume
college-lecturer-resume-sample
commercial-assistant-resume-sample
compliance-officer-resume-samples
computer-teacher-resume-format
computer-teacher-resume-sample
cordova-developer-resume-sample
useful information..nice..
ReplyDeletedevops-engineer-resume-samples
digital-marketing-resume-samples
digital-marketing-resume-samples
electronics-engineer-resume-sample
engineering-lab-technician-resume-samples
english-teacher-cv-sample
english-teacher-resume-example
english-teacher-resume-sample
excel-expert-resume-sample
executive-secretary-resume-samples
Very Nice Blog…Thanks for sharing this information with us. Here am sharing some information about training institute.
ReplyDeletebest devops online training in hyderabad
Great information and Thank you so mush for the publishing such type of information with us. IFuturetechnologies.in - Best Computer Institute in kalyan & Thane.
ReplyDeleteThank you for this wonderful post, great article, keep up the excellent work.
ReplyDeleteJava training institute in Hyderabad