Get the App
SLTechnology News&Howtos  ›  Database  › 

How to realize the alternative method of ROLLUP in MySQL

Shulou Source: shulou.com Published: 2022-05-31 11:35:55 11月07日 Update

Editor to share with you how to achieve the alternative to ROLLUP in MySQL, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

After extracting the data from MySQL and using ROLLUP statistics, you want to add the project name to the left column of the data and use SQL

Sql code

SELECT (CASE WHEN ISNULL (PLAYERNO) THEN PLAYERNO=TOTAL ELSE PLAYERNO END) AS PLAYERNO,SUM (AMOUNT) FROM penalties

GROUP BY PLAYERNO WITH ROLLUP

The result is:

Like this

+-+ +

| | PLAYERNO | SUM (AMOUNT) |

+-+ +

| | 6 | 100.00 | |

| | 8 | 25.00 |

| | 27 | 175.00 | |

| | 44 | 130.00 | |

| | 104 | 50.00 |

| | NULL | 480.00 | |

+-+ +

6 rows in set, 1 warning (0.00 sec)

Displayed as a null value, modified as follows:

Sql code

SELECT PLAYERNO,SUM (AMOUNT) FROM penalties

GROUP BY PLAYERNO

UNION

SELECT TOTAL,SUM (AMOUNT)

FROM penalties

Display the results:

+-+ +

| | PLAYERNO | SUM (AMOUNT) |

+-+ +

| | 6 | 100.00 | |

| | 8 | 25.00 |

| | 27 | 175.00 | |

| | 44 | 130.00 | |

| | 104 | 50.00 |

| | TOTAL | 480.00 | |

+-+ +

6 rows in set (0.00 sec)

The above is all the content of the article "how to implement the alternative to ROLLUP in MySQL". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Articles methods code content data results not much name most more knowledge industry information information channels projects channels China and Canada reference learning help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei OPPO Reno macOS Apple Linux