If we use an explicit sort order (ASC or DESC) with the "WITH ROLLUP" modifier for the column names in the GROUP BY list, the summary rows added by ROLLUP Will still appear after the calculated row, regardless of sort order.
We know that the default sort order is ascending, so in the example below, if we don't use any explicit sort order, the output is as follows -
mysql> Select sr, SUM(Price) AS Price from ratelist Group by sr with rollup; +-----+-------+ | sr | Price | +-----+-------+ | 1 | 502 | | 2 | 630 | | 3 | 1005 | | 4 | 850 | | 5 | 250 | |NULL | 3237 | +-----+-------+ 6 rows in set (0.00 sec)
Now define the sort order as DESC , we will get the output from the above query as shown below -
mysql> Select sr, SUM(Price) AS Price from ratelist Group by sr DESC with rollup; +-----+-------+ | sr | Price | +-----+-------+ | 5 | 250 | | 4 | 850 | | 3 | 1005 | | 2 | 630 | | 1 | 502 | |NULL | 3237 | +-----+-------+ 6 rows in set (0.00 sec)
From the output it can be seen that although the sort order is changed to descending, the summary rows appear after the rows where they are calculated.
The above is the detailed content of What is the impact on the summary output when I use an explicit sort order (ASC or DESC) on the column names in the GROUP BY list with the 'WITH ROLLUP' modifier?. For more information, please follow other related articles on the PHP Chinese website!