我有一张这样的表:
-----------------
| Name | Amount|
-----------------
| A | 100 |
| B | 200 |
| C | 100 |
| D | 200 |
| E | 100 |
| Total | 700 |
-----------------
我希望能够为每个人总计,并将其余部分显示为总数以进行比较。所以对于例如:
-----------------
| Name | Amount|
-----------------
| A | 100 |
| Others| 600 |
| Total | 700 |
-----------------
当我执行GROUP BY
和WITH ROLLUP
时,我能够获得原始表格,但无法弄清楚如何生成第二张表格。< / p>
答案 0 :(得分:0)
SELECT NAME, AMOUNT FROM
(
SELECT
CASE WHEN A THEN A ELSE OTHERS END AS NAME, AMOUNT
FROM MyTable
) T
GROUP BY ROLLUP NAME, AMOUNT