The GROUP BY
clause permits a WITH ROLLUP
modifier that causes summary output to include extra rows that represent higher-level (that is, super-aggregate) summary operations. ROLLUP
thus enables you to answer questions at multiple levels of analysis with a single query. For example, ROLLUP
can be used to provide support for OLAP (Online Analytical Processing) operations.
Suppose that a sales
table has year
, country
, product
, and profit
columns for recording sales profitability:
To summarize table contents per year, use a simple GROUP BY
like this:
The NULL value in the year column identifies the grand total super-aggregate line. ROLLUP has a more complex effect when there are multiple GROUP BY columns. In this case, each time there is a change in value in any but the last grouping column, the query produces an extra super-aggregate summary row. Addtotals Description. The addtotals command computes the arithmetic sum of all numeric fields for each search result. The results appear in the Statistics tab. You can specify a list of fields that you want the sum for, instead of calculating every numeric field.
GRAND TOTAL 45.6 20.8 8.8 0.8 76.0 OVERALL TOTAL 3 7.5 83.2 46.0 22.0 2.0 153.2 30-Grand Total 9 DIPTEROCARP GRAND TOTAL 26.1 15.8 7. 1999: 2000 2001: 2002 2003: 2004 2005: 2006 2007: 2008 2009: 2010 2011: 2012 2013: 2014 2015: Total January.
The output shows the total (aggregate) profit for each year. To also determine the total profit summed over all years, you must add up the individual values yourself or run an additional query. Or you can use ROLLUP
, which provides both levels of analysis with a single query. Adding a WITH ROLLUP
modifier to the GROUP BY
clause causes the query to produce another (super-aggregate) row that shows the grand total over all year values:
The NULL
value in the year
column identifies the grand total super-aggregate line.
ROLLUP
has a more complex effect when there are multiple GROUP BY
columns. In this case, each time there is a change in value in any but the last grouping column, the query produces an extra super-aggregate summary row.
For example, without ROLLUP
, a summary of the sales
table based on year
, country
, and product
might look like this, where the output indicates summary values only at the year/country/product level of analysis:
With ROLLUP
added, the query produces several extra rows:
Now the output includes summary information at four levels of analysis, not just one:
Following each set of product rows for a given year and country, an extra super-aggregate summary row appears showing the total for all products. These rows have the
product
column set toNULL
.Following each set of rows for a given year, an extra super-aggregate summary row appears showing the total for all countries and products. These rows have the
country
andproducts
columns set toNULL
.Finally, following all other rows, an extra super-aggregate summary row appears showing the grand total for all years, countries, and products. This row has the
year
,country
, andproducts
columns set toNULL
.
The NULL
indicators in each super-aggregate row are produced when the row is sent to the client. The server looks at the columns named in the GROUP BY
clause following the leftmost one that has changed value. For any column in the result set with a name that matches any of those names, its value is set to NULL
. (If you specify grouping columns by column position, the server identifies which columns to set to NULL
by position.)
Because the NULL
values in the super-aggregate rows are placed into the result set at such a late stage in query processing, you can test them as NULL
values only in the select list or HAVING
clause. You cannot test them as NULL
values in join conditions or the WHERE
clause to determine which rows to select. For example, you cannot add WHERE product IS NULL
to the query to eliminate from the output all but the super-aggregate rows.
The NULL
values do appear as NULL
on the client side and can be tested as such using any MySQL client programming interface. However, at this point, you cannot distinguish whether a NULL
represents a regular grouped value or a super-aggregate value. To test the distinction, use the GROUPING()
function, described later.
Grand Total 6 0 8 0 Download
Nzbvortex 3 0 2 – lightweight usenet nzb download client. Previously, MySQL did not allow the use of DISTINCT
or ORDER BY
in a query having a WITH ROLLUP
option. This restriction is lifted in MySQL 8.0.12 and later. (Bug #87450, Bug #86311, Bug #26640100, Bug #26073513)
For GROUP BY .. WITH ROLLUP
queries, to test whether NULL
values in the result represent super-aggregate values, the GROUPING()
function is available for use in the select list, HAVING
clause, and (as of MySQL 8.0.12) ORDER BY
clause. For example, GROUPING(year)
returns 1 when NULL
in the year
column occurs in a super-aggregate row, and 0 otherwise. Similarly, GROUPING(country)
and GROUPING(product)
return 1 for super-aggregate NULL
values in the country
and product
columns, respectively:
Instead of displaying the GROUPING()
results directly, you can use GROUPING()
to substitute labels for super-aggregate NULL
values:
With multiple expression arguments, GROUPING()
returns a result representing a bitmask the combines the results for each expression, with the lowest-order bit corresponding to the result for the rightmost expression. For example, GROUPING(year, country, product)
is evaluated like this:
The result of such a GROUPING()
is nonzero if any of the expressions represents a super-aggregate NULL
, so you can return only the super-aggregate rows and filter out the regular grouped rows like this:
The sales
table contains no NULL
values, so all NULL
values in a ROLLUP
result represent super-aggregate values. When the data set contains NULL
values, ROLLUP
summaries may contain NULL
values not only in super-aggregate rows, but also in regular grouped rows. GROUPING()
enables these to be distinguished. Suppose that table t1
contains a simple data set with two grouping factors for a set of quantity values, where NULL
indicates something like 'other' or 'unknown':
A simple ROLLUP
operation produces these results, in which it is not so easy to distinguish NULL
values in super-aggregate rows from NULL
values in regular grouped rows:
Using GROUPING()
to substitute labels for the super-aggregate NULL
values makes the result easier to interpret:
The following discussion lists some behaviors specific to the MySQL implementation of ROLLUP
. Firefox 72 offline installer. Movist 1 3 17 download free.
Prior to MySQL 8.0.12, when you use ROLLUP
, you cannot also use an ORDER BY
clause to sort the results. In other words, ROLLUP
and ORDER BY
were mutually exclusive in MySQL. However, you still have some control over sort order. To work around the restriction that prevents using ROLLUP
with ORDER BY
and achieve a specific sort order of grouped results, generate the grouped result set as a derived table and apply ORDER BY
to it. For example:
0-8 0 Locomotive
As of MySQL 8.0.12, ORDER BY
and ROLLUP
can be used together, which enables the use of ORDER BY
and GROUPING()
to achieve a specific sort order of grouped results. For example:
In both cases, the super-aggregate summary rows sort with the rows from which they are calculated, and their placement depends on sort order (at the end for ascending sort, at the beginning for descending sort).
The output shows the total (aggregate) profit for each year. To also determine the total profit summed over all years, you must add up the individual values yourself or run an additional query. Or you can use ROLLUP
, which provides both levels of analysis with a single query. Adding a WITH ROLLUP
modifier to the GROUP BY
clause causes the query to produce another (super-aggregate) row that shows the grand total over all year values:
The NULL
value in the year
column identifies the grand total super-aggregate line.
ROLLUP
has a more complex effect when there are multiple GROUP BY
columns. In this case, each time there is a change in value in any but the last grouping column, the query produces an extra super-aggregate summary row.
For example, without ROLLUP
, a summary of the sales
table based on year
, country
, and product
might look like this, where the output indicates summary values only at the year/country/product level of analysis:
With ROLLUP
added, the query produces several extra rows:
Now the output includes summary information at four levels of analysis, not just one:
Following each set of product rows for a given year and country, an extra super-aggregate summary row appears showing the total for all products. These rows have the
product
column set toNULL
.Following each set of rows for a given year, an extra super-aggregate summary row appears showing the total for all countries and products. These rows have the
country
andproducts
columns set toNULL
.Finally, following all other rows, an extra super-aggregate summary row appears showing the grand total for all years, countries, and products. This row has the
year
,country
, andproducts
columns set toNULL
.
The NULL
indicators in each super-aggregate row are produced when the row is sent to the client. The server looks at the columns named in the GROUP BY
clause following the leftmost one that has changed value. For any column in the result set with a name that matches any of those names, its value is set to NULL
. (If you specify grouping columns by column position, the server identifies which columns to set to NULL
by position.)
Because the NULL
values in the super-aggregate rows are placed into the result set at such a late stage in query processing, you can test them as NULL
values only in the select list or HAVING
clause. You cannot test them as NULL
values in join conditions or the WHERE
clause to determine which rows to select. For example, you cannot add WHERE product IS NULL
to the query to eliminate from the output all but the super-aggregate rows.
The NULL
values do appear as NULL
on the client side and can be tested as such using any MySQL client programming interface. However, at this point, you cannot distinguish whether a NULL
represents a regular grouped value or a super-aggregate value. To test the distinction, use the GROUPING()
function, described later.
Grand Total 6 0 8 0 Download
Nzbvortex 3 0 2 – lightweight usenet nzb download client. Previously, MySQL did not allow the use of DISTINCT
or ORDER BY
in a query having a WITH ROLLUP
option. This restriction is lifted in MySQL 8.0.12 and later. (Bug #87450, Bug #86311, Bug #26640100, Bug #26073513)
For GROUP BY .. WITH ROLLUP
queries, to test whether NULL
values in the result represent super-aggregate values, the GROUPING()
function is available for use in the select list, HAVING
clause, and (as of MySQL 8.0.12) ORDER BY
clause. For example, GROUPING(year)
returns 1 when NULL
in the year
column occurs in a super-aggregate row, and 0 otherwise. Similarly, GROUPING(country)
and GROUPING(product)
return 1 for super-aggregate NULL
values in the country
and product
columns, respectively:
Instead of displaying the GROUPING()
results directly, you can use GROUPING()
to substitute labels for super-aggregate NULL
values:
With multiple expression arguments, GROUPING()
returns a result representing a bitmask the combines the results for each expression, with the lowest-order bit corresponding to the result for the rightmost expression. For example, GROUPING(year, country, product)
is evaluated like this:
The result of such a GROUPING()
is nonzero if any of the expressions represents a super-aggregate NULL
, so you can return only the super-aggregate rows and filter out the regular grouped rows like this:
The sales
table contains no NULL
values, so all NULL
values in a ROLLUP
result represent super-aggregate values. When the data set contains NULL
values, ROLLUP
summaries may contain NULL
values not only in super-aggregate rows, but also in regular grouped rows. GROUPING()
enables these to be distinguished. Suppose that table t1
contains a simple data set with two grouping factors for a set of quantity values, where NULL
indicates something like 'other' or 'unknown':
A simple ROLLUP
operation produces these results, in which it is not so easy to distinguish NULL
values in super-aggregate rows from NULL
values in regular grouped rows:
Using GROUPING()
to substitute labels for the super-aggregate NULL
values makes the result easier to interpret:
The following discussion lists some behaviors specific to the MySQL implementation of ROLLUP
. Firefox 72 offline installer. Movist 1 3 17 download free.
Prior to MySQL 8.0.12, when you use ROLLUP
, you cannot also use an ORDER BY
clause to sort the results. In other words, ROLLUP
and ORDER BY
were mutually exclusive in MySQL. However, you still have some control over sort order. To work around the restriction that prevents using ROLLUP
with ORDER BY
and achieve a specific sort order of grouped results, generate the grouped result set as a derived table and apply ORDER BY
to it. For example:
0-8 0 Locomotive
As of MySQL 8.0.12, ORDER BY
and ROLLUP
can be used together, which enables the use of ORDER BY
and GROUPING()
to achieve a specific sort order of grouped results. For example:
In both cases, the super-aggregate summary rows sort with the rows from which they are calculated, and their placement depends on sort order (at the end for ascending sort, at the beginning for descending sort).
LIMIT
can be used to restrict the number of rows returned to the client. LIMIT
is applied after ROLLUP
, so the limit applies against the extra rows added by ROLLUP
. For example:
Using LIMIT
with ROLLUP
may produce results that are more difficult to interpret, because there is less context for understanding the super-aggregate rows.
A MySQL extension permits a column that does not appear in the GROUP BY
list to be named in the select list. (For information about nonaggregated columns and GROUP BY
, see Section 12.20.3, 'MySQL Handling of GROUP BY'.) In this case, the server is free to choose any value from this nonaggregated column in summary rows, and this includes the extra rows added by WITH ROLLUP
. For example, in the following query, country
is a nonaggregated column that does not appear in the GROUP BY
list and values chosen for this column are nondeterministic:
This behavior is permitted when the ONLY_FULL_GROUP_BY
SQL mode is not enabled. If that mode is enabled, the server rejects the query as illegal because country
is not listed in the GROUP BY
clause. With ONLY_FULL_GROUP_BY
enabled, you can still execute the query by using the ANY_VALUE()
function for nondeterministic-value columns:
Grand Total 6 0 8 0 09
Issues Of Alleged Discrimination | Bases Of Allleged Discrimination | Total Bases by Issue | Total Complaints by Issue | Total Complainants by Issue | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Race | Color | Religion | Reprisal | Sex | PDA | National Origin | Equal Pay Act | Age | Disability | GINA | |||||||||||||
American Indian/ Alaska Native | Asian | Native Hawaiian/Other Pacific Islander | Back / African American | White | Two or More Races | Male | Female | Hispanic | Other | Male | Female | Mental | Physical | ||||||||||
Appointment/Hire | 10 | 18 | 4 | 180 | 49 | 6 | 71 | 25 | 233 | 104 | 125 | 3 | 33 | 63 | 0 | 0 | 303 | 72 | 191 | 3 | 1,493 | 756 | 737 |
Assignment of Duties | 24 | 30 | 7 | 409 | 120 | 20 | 171 | 59 | 757 | 182 | 426 | 2 | 64 | 123 | 0 | 0 | 462 | 96 | 281 | 2 | 3,235 | 1,479 | 1,459 |
Awards | 3 | 8 | 6 | 86 | 19 | 3 | 36 | 16 | 168 | 38 | 65 | 0 | 11 | 20 | 0 | 0 | 98 | 20 | 44 | 0 | 641 | 277 | 267 |
Conversion To Full Time | 0 | 0 | 0 | 8 | 2 | 0 | 5 | 3 | 10 | 3 | 9 | 0 | 2 | 2 | 0 | 0 | 10 | 3 | 9 | 0 | 66 | 30 | 30 |
Disciplinary Action | 32 | 84 | 5 | 974 | 307 | 30 | 456 | 145 | 1,991 | 549 | 856 | 6 | 123 | 235 | 0 | 0 | 1,153 | 298 | 825 | 2 | 8,071 | 3,654 | 3,600 |
A. Demotion | 0 | 1 | 0 | 27 | 7 | 0 | 8 | 3 | 48 | 18 | 22 | 0 | 8 | 6 | 0 | 0 | 40 | 8 | 9 | 0 | 205 | 104 | 101 |
B. Reprimand | 16 | 26 | 2 | 282 | 94 | 10 | 147 | 43 | 658 | 173 | 264 | 3 | 37 | 81 | 0 | 0 | 380 | 63 | 246 | 0 | 2,525 | 1,146 | 1,130 |
C. Suspension | 4 | 21 | 0 | 286 | 86 | 12 | 122 | 40 | 634 | 153 | 230 | 2 | 38 | 56 | 0 | 0 | 317 | 80 | 220 | 2 | 2,303 | 1,052 | 1,033 |
D. Removal | 7 | 24 | 1 | 194 | 65 | 4 | 99 | 35 | 341 | 102 | 199 | 1 | 24 | 49 | 0 | 0 | 245 | 104 | 228 | 0 | 1,722 | 749 | 740 |
5. Other | 5 | 12 | 2 | 185 | 55 | 4 | 80 | 24 | 310 | 103 | 141 | 0 | 16 | 43 | 0 | 0 | 171 | 43 | 122 | 0 | 1,316 | 603 | 596 |
Duty Hours | 3 | 16 | 1 | 157 | 76 | 6 | 94 | 40 | 330 | 97 | 193 | 1 | 13 | 42 | 0 | 0 | 204 | 54 | 170 | 0 | 1,497 | 687 | 683 |
Evaluation/Appraisal | 9 | 37 | 8 | 367 | 79 | 10 | 154 | 57 | 812 | 157 | 300 | 0 | 46 | 112 | 0 | 0 | 436 | 101 | 212 | 0 | 2,897 | 1,362 | 1,329 |
Examination/Test | 0 | 1 | 0 | 15 | 3 | 0 | 7 | 2 | 17 | 7 | 7 | 0 | 7 | 8 | 0 | 0 | 11 | 4 | 13 | 0 | 102 | 55 | 55 |
Harassment | 45 | 125 | 23 | 1,515 | 483 | 71 | 619 | 282 | 3,240 | 790 | 2,050 | 9 | 276 | 444 | 0 | 0 | 1,678 | 521 | 1,216 | 5 | 13,392 | 6,432 | 6,177 |
A. Non-Sexual | 45 | 125 | 23 | 1,515 | 483 | 71 | 619 | 282 | 3,083 | 692 | 1,608 | 9 | 276 | 444 | 0 | 0 | 1,678 | 521 | 1,216 | 5 | 12,695 | 5,863 | 5,609 |
B. Sexual | 157 | 98 | 442 | 0 | 697 | 569 | 568 | ||||||||||||||||
Medical Examination | 1 | 1 | 0 | 9 | 3 | 0 | 10 | 2 | 49 | 11 | 11 | 0 | 5 | 4 | 0 | 0 | 27 | 20 | 47 | 1 | 201 | 94 | 93 |
Pay Including Overtime | 6 | 17 | 2 | 226 | 82 | 6 | 110 | 45 | 418 | 129 | 212 | 1 | 18 | 75 | 8 | 28 | 251 | 47 | 207 | 0 | 1,888 | 863 | 841 |
Promotion/Non-Selection | 23 | 80 | 11 | 990 | 187 | 26 | 284 | 126 | 881 | 337 | 464 | 2 | 137 | 179 | 0 | 0 | 1,084 | 124 | 369 | 2 | 5,306 | 2,683 | 2,595 |
Reassignment | 9 | 30 | 2 | 223 | 71 | 11 | 99 | 36 | 423 | 97 | 246 | 2 | 39 | 79 | 0 | 0 | 305 | 69 | 200 | 1 | 1,942 | 884 | 870 |
A. Denied | 2 | 18 | 0 | 78 | 20 | 4 | 39 | 12 | 135 | 33 | 80 | 1 | 10 | 31 | 0 | 0 | 87 | 28 | 70 | 1 | 649 | 303 | 300 |
B. Directed | 7 | 12 | 2 | 145 | 51 | 7 | 60 | 24 | 288 | 64 | 166 | 1 | 29 | 48 | 0 | 0 | 218 | 41 | 130 | 0 | 1,293 | 581 | 570 |
Reasonable Accommodation | 65 | 626 | 261 | 956 | 0 | 1,908 | 1,366 | 1,327 | |||||||||||||||
Reinstatement | 0 | 2 | 0 | 7 | 1 | 0 | 7 | 2 | 22 | 5 | 5 | 0 | 3 | 6 | 0 | 0 | 15 | 5 | 12 | 0 | 92 | 44 | 44 |
Retirement | 0 | 1 | 0 | 17 | 13 | 0 | 10 | 6 | 51 | 14 | 14 | 0 | 2 | 8 | 0 | 0 | 73 | 19 | 41 | 0 | 269 | 139 | 136 |
Termination | 14 | 32 | 3 | 368 | 113 | 15 | 131 | 74 | 457 | 157 | 294 | 2 | 67 | 123 | 0 | 0 | 363 | 181 | 392 | 11 | 2,797 | 1,434 | 1,419 |
Terms/Conditions Of Employment | 17 | 46 | 5 | 632 | 225 | 20 | 312 | 119 | 1,364 | 315 | 640 | 6 | 83 | 172 | 0 | 0 | 777 | 203 | 626 | 0 | 5,562 | 2,492 | 2,418 |
Time and Attendance | 11 | 30 | 3 | 367 | 124 | 14 | 182 | 75 | 840 | 176 | 392 | 3 | 43 | 101 | 0 | 0 | 402 | 159 | 448 | 1 | 3,371 | 1,434 | 1,398 |
Training | 2 | 20 | 1 | 205 | 41 | 9 | 70 | 22 | 287 | 82 | 150 | 1 | 27 | 54 | 0 | 0 | 158 | 42 | 111 | 1 | 1,283 | 576 | 571 |
U. Other | 6 | 10 | 0 | 168 | 56 | 9 | 81 | 24 | 371 | 95 | 133 | 0 | 28 | 39 | 0 | 0 | 215 | 63 | 203 | 0 | 1,501 | 708 | 683 |
Total Issues By Bases | 215 | 588 | 81 | 6,923 | 2,054 | 256 | 2,909 | 1,225 | 13,347 | 3,345 | 6,592 | 38 | 1,027 | 1,889 | 8 | 28 | 8,025 | 2,362 | 6,573 | 29 | |||
Total Complaints Filed By Bases | 136 | 364 | 60 | 4,389 | 1,269 | 143 | 1,754 | 681 | 7,553 | 2,104 | 3,930 | 23 | 642 | 1,105 | 8 | 28 | 5,105 | 1,353 | 3,814 | 16 | |||
Total Complainants By Bases | 133 | 352 | 52 | 4,209 | 1,235 | 139 | 1,686 | 656 | 6,942 | 2,025 | 3,805 | 23 | 626 | 1,061 | 8 | 27 | 4,896 | 1,282 | 3,639 | 15 |