如何将查询出来的多条记录按照指定的两个字段汇总成一行记录
这是我现有语句
select FYear ,FAccountID,'B','' ,'111','111',
case when FPeriod='1' and FBeginBalance>0 then ABS(convert(money,FBeginBalance)) ELSE 0 end ,
case when FPeriod='1' and FBeginBalance<0 then ABS(convert(money,FBeginBalance)) ELSE 0 end ,
case when FPeriod='1' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='1' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='2' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='2' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='3' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='3' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='4' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='4' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='5' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='5' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='6' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='6' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='7' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='7' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='8' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='8' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='9' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='9' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='10' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='10' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='11' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='11' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='12' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='12' then convert(money,FDebit) ELSE 0 end,
case when FPeriod='13' then convert(money,FCredit) ELSE 0 end,
case when FPeriod='13' then convert(money,FDebit) ELSE 0 end,'0'
from t_Balance where FCurrencyID=1 and FYear='2008'and faccountid='1003'
查询出来结果为图片1
需要将查询出来的表按照前两个字段相同的话就汇总成一条记录,后面为金额字段则汇总求和