Question

Differentiate single grouping sets from multiple grouping sets in SQL

Differentiate single grouping sets from multiple grouping sets in SQL

0 0
Add a comment Improve this question Transcribed image text
Answer #1

By definition, a grouping set is a group of columns by which you group. Typically, a single query with an aggregate defines a single grouping set.

For EX:

Suppose we have created a table sales.sales_summary.

The following query defines a grouping set that includes brand and category which is denoted as (brand, category). The query returns the sales amount grouped by brand and category:

SELECT brand, category, SUM (sales) sales FROM sales.sales_summary GROUP BY brand, category ORDER BY brand, category;

Output:

brand category sales Electra Children Bicycles 207606.0000 Electra Comfort Bicycles 271542.0000 Electra Cruisers Bicycles 694

The following query returns the sales amount by brand. It defines a grouping set (brand):

SELECT brand, SUM (sales) sales FROM sales.sales_summary GROUP BY brand ORDER BY brand; 

Output:

Here we are using a ORDER BY clause to show a single grouping set.

Add a comment
Know the answer?
Add Answer to:
Differentiate single grouping sets from multiple grouping sets in SQL
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT