select 分组字段=isnull(a.分组字段,b.分组字段),本月,所有月份累计 from( select 分组字段,本月=sum(汇总字段) from 表 where 月份=@月份 group by 分组字段 )a full join( select 分组字段,本月=sum(汇总字段) from 表 where 月份<=@月份 group by 分组字段 )b on a.分组字段=b.分组字段
已调试成功,多谢老大,如下: select cpartcode=isnull(a.cpartcode,b.cpartcode),本月,所有月份 from (select cpartcode,sum(ithsl) 本月 from _03jltz where dregistdate between '2004/3/1' and '2004/8/8' group by cpartcode ) a full join( select cpartcode,sum(ithsl) 所有月份 from _03jltz where dregistdate<='2004/8/8' group by cpartcode) b on a.cpartcode=b.cpartcode 这种句法真是很少见,还有那个full join ,在联机帮助中找不到,也许我太菜了,^_^
from(
select 分组字段,本月=sum(汇总字段)
from 表
where 月份=@月份
group by 分组字段
)a full join(
select 分组字段,本月=sum(汇总字段)
from 表
where 月份<=@月份
group by 分组字段
)b on a.分组字段=b.分组字段
select cpartcode=isnull(a.cpartcode,b.cpartcode),本月,所有月份
from (select cpartcode,sum(ithsl) 本月 from _03jltz where dregistdate between '2004/3/1' and '2004/8/8' group by cpartcode ) a
full join(
select cpartcode,sum(ithsl) 所有月份 from _03jltz where dregistdate<='2004/8/8' group by cpartcode) b
on a.cpartcode=b.cpartcode
这种句法真是很少见,还有那个full join ,在联机帮助中找不到,也许我太菜了,^_^