日期:2014-05-17 浏览次数:20511 次
select a.月份,isnull(b.出金,0), isnull(b.入金,0), isnull(b.剩余金额 ,0)
from (
select 1 as 月份 union all
select 2 union all
select 3 union all
select 4 union all
select 5 union all
select 6 union all
select 7 union all
select 8 union all
select 9 union all
select 10 union all
select 11 union all
select 12 union all
) a
left join
(
select month(日期字段) as 月份,sum(出金) as 出金,sum(入金) as 入金,sum(剩余金额) as 剩余金额
from tb where year(期字段)=2012
grouy by month(日期字段)
) b
on a.月份=b.月份