按名称分组的总和总和金额

时间:2015-09-01 12:41:06

标签: sql

select CandidateName, SUM(Amount) as Amount
from MaseHisab
where Member = 'ABC+DEF+GHI'
group by CandidateName




CandidateName   Amount
jain            72.00
rakesh          30.00
shams           110.00

1 个答案:

答案 0 :(得分:1)

如果您正在使用SQL-Server 使用with rollup。这将为您提供

末尾的金额列的总和
select isnull(CandidateName,'Total'),SUM(Amount) as Amount
from MaseHisab
where Member='ABC+DEF+GHI' group by CandidateName
with rollup

O / P

CandidateName   Amount
jain            72.00
rakesh          30.00
shams           110.00
NULL            212.00

修改

使用isnull。见上面的查询

isnull(CandidateName,'Total')

如果您正在使用其他数据库

COALESCE(CandidateName,'Total')