Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Step 7: All GROUPING calls are evaluated for each group and appended to
each row in each group. This example doesnt have any GROUPING calls, but
if it did, each call would result in yet another item appended to each row con-
taining a 1 or a 0. The GROUPING function is described in Section 3.15,
GROUP BY ROLLUP Clause.
Step 8: The HAVING clause is applied to eliminate entire groups.
In this case, the HAVING COUNT(*) > 1 clause eliminates the two sin-
gle-row groups where a = 100, and that means the candidate result set no longer
adds up to the subtotal R2 or the grand total R1:
t1. t1. t2. t2. t3. t3. COUNT SUM
key_1 non_key_1 key_1 key_2 key_1 non_key_1 a b AS c AS d
===== ========= ===== ===== ===== ========= === ==== ===== ====
R1 NULL NULL NULL NULL NULL NULL NULL NULL 8 2664
-------------------------------------------------------------------------
R2 NULL NULL NULL NULL NULL NULL 100 NULL 2 666
-------------------------------------------------------------------------
R3 NULL NULL NULL NULL NULL NULL 200 NULL 6 1998
-------------------------------------------------------------------------
E 2 2 2 21 3 333 200 3000 3 999
F 2 2 2 22 3 333 200 3000 3 999
G 2 2 2 23 3 333 200 3000 3 999
-------------------------------------------------------------------------
H 2 2 2 21 4 333 200 4000 3 999
I 2 2 2 22 4 333 200 4000 3 999
J 2 2 2 23 4 333 200 4000 3 999
The HAVING COUNT(*) > 1 clause doesnt affect any of the ROLLUP sum-
mary rows in this example even though they appear as single-row groups; thats
because COUNT(*) returns 8, 2, and 6 for each of the ROLLUP rows labeled
R1, R2, and R3, respectively. In other words, COUNT(*) for a ROLLUP row
counts the number of rows that the ROLLUP row represents. If the HAVING
clause had specified COUNT(*) > 2 instead, the ROLLUP row labeled R2
would have been eliminated at this point.