如何在sql存储过程中获取包含总计的列表?

时间:2012-08-30 07:51:49

标签: sql sql-server stored-procedures

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

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

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

编辑:我在T-Sql中使用Sql server

1 个答案:

答案 0 :(得分:1)

这适用于所有类型的SQL。

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

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

相关问题