Selectsr,SUM(Price)ASPricefromratelistGroupbysrwithrollup;+-----+---- ---+|sr |Price|+-----+-----"/> Selectsr,SUM(Price)ASPricefromratelistGroupbysrwithrollup;+-----+---- ---+|sr |Price|+-----+-----">

Home  >  Article  >  Database  >  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?

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?

王林
王林forward
2023-08-25 18:33:02540browse

当我对 GROUP BY 列表中的列名以及“WITH ROLLUP”修饰符使用显式排序顺序(ASC 或 DESC)时,会对摘要输出产生什么影响?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete