Home > Database > Mysql Tutorial > body text

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?

王林
Release: 2023-08-25 18:33:02
forward
573 people have browsed it

当我对 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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!