0

我想在一个列表中得到这样的结果。

TYPE    | subtype | Total
  A     | z       | 5
  A     | y       | 3
total A | NULL    | 8
  B     | i       | 6
total B | Null    | 6

如何在 sql 存储过程中执行此操作?

编辑:我在 T-Sql for Sql server 中工作

4

1 回答 1

1

这适用于所有类型的 SQL。

Select type, subtype, total from source
union all
Select type, 'Total', sum(total) from source group by type
order by type

如果您有特定类型的 SQL,可能会有更有效的解决方案

于 2012-08-30T07:54:18.197 回答