《Mysql实例mysql中ROLLUP的替代方法(实例)》要点:
本文介绍了Mysql实例mysql中ROLLUP的替代方法(实例),希望对您有用。如果有疑问,可以联系我们。
导读:从MySQL中提取数据,使用ROLLUP统计后,想在数据左边列中加入项目名称,使用SQL:
SELECT (CASE WHEN ISNULL(PLAYERNO) THEN PLAYERNO=...
MYSQL教程从MySQL中提取数据,使用ROLLUP统计后,想在数据左边列中加入项目名称,使用SQL:
SELECT (CASE WHEN ISNULL(PLAYERNO) THEN PLAYERNO='TOTAL' ELSE PLAYERNO END) AS PLAYERNO,SUM(AMOUNT) FROM penalties
GROUP BY PLAYERNO WITH ROLLUP
MYSQL教程输出结果:
+----------+-------------+
| 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)
MYSQL教程显示为空值,修改如下:
SELECT PLAYERNO,SUM(AMOUNT) FROM penalties
GROUP BY PLAYERNO
UNION
SELECT 'TOTAL',SUM(AMOUNT)
FROM penalties
MYSQL教程显示结果:
+----------+-------------+
| 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)
MYSQL教程问题:虽然这样也可以显示出数据,但却没有了ROLLUP的简洁,哪位有更好的办法,欢迎分享下.
《Mysql实例mysql中ROLLUP的替代方法(实例)》是否对您有启发,欢迎查看更多与《Mysql实例mysql中ROLLUP的替代方法(实例)》相关教程,学精学透。维易PHP学院为您提供精彩教程。
转载请注明本页网址:
http://www.vephp.com/jiaocheng/12749.html