Chapter 5: Grouping and Windowing Flashcards
What is a grouping set?
Group the data by a set of attributes (columns).
When a query becomes a grouped query?
A query becomes a grouped query when you use a group function, a GROUP BY clause, or both.
What does return a grouped query?
Grouped queries return one result row per group.
What is the difference between COUNT(column) and COUNT(*)?
The former ignores the NULL and the latter doesn’t ignore NULL.
Can the NULL be grouped in a GROUP BY?
Yes, it can.
If I want define more than a grouping set, which clause can I use?
GROUPING SETS, ROLLUP or CUBE.
What does do the GROUPING SETS clause?
List all grouping sets that the user want define in the query.
What’s the function of empty set represented by a empty parentheses () in a GROUPING SETS clause?
It calculates the grant total.
What does do the CUBE clause?
Accept a list of expressions and define all possible grouping sets that can be generated from the inputs.
What does do the ROLLUP clause?
Given a set of columns, it’ll detailed the most right column. For example, GROUP BY ROLLUP(col1, col2, col3) will produce 4 groups: (1) grouped by col1, col2, col3. (2) grouped by col1, col2. (3) grouped by col1. (4) (), this is the grand total.
What does do the function GROUPING?
Return 1 when the column value is added by the clause ROLLUP or CUBE, or return 0 when the column value is from the grouping set.
What is pivoting data?
Is a techinque that groups and aggregates data.
What are the elements which need to be identified in a pivot query?
- What I want to see on rows? This is known as grouping element.
- What I want to see on columns? This is known as spreading element.
- What I want to see in the intersection of a column and a row? This is known as data or aggregation element.
What is unpivoting data?
Unpivoting data can be considered the inverse of pivoting. The starting point is some pivoted
data. When unpivoting data, you rotate the input data from a state of columns to a state of
rows.
What is the difference between a Group Aggregate Function and a Window Aggregate Function?
A group aggregate function is applied to per group from a result set, whereas a window aggregate function is applied to a windows of rows.