select xm as '项目',sj as '时间',sum(hj) as '合计', sum(lj) as '累计'
from
(select xm,sj,sum(jrs-kss) as hj,0 as lj
from semxb
where ZBGUID in (select GUID from SERBZB) and TBRQ = '2007-08-01'
group by xm,sj
union
select xm,sj,0,sum(jrs-kss)
from semxb
where ZBGUID in (select GUID from SERBZB)
group by xm,sj) T1
group by xm,sj
用case 不好么?
select xm as '项目',sj as '时间',sum(jrs-kss) as '累计',sum(case when TBRQ = '2007-08-01' then jrs-kss else 0 end) as '累计'
from semxb
where ZBGUID in (select GUID from SERBZB)
group by xm,sj