select a.xh,c.feiyong mq,d.hj dh,f.feiyong db ,g.shb as shb
From hishtxftb a,
hishtfwtb b ,
(select fhid,sum(feiyong) feiyong from hismqtb group by fhid) c,
(select fhid,sum(hj) hj from hisdhtb group by fhid) d ,
(select fhid,sum(feiyong) feiyong from hisdbtb group by fhid) f ,
(select fhid,sum(g.psf+g.fy) shb from hisshbtb group by fhid) g
where
a.xh=b.xh and b.fhid=c.fhid and b.fhid=d.fhid and b.fhid=f.fhid and b.fhid=g.fhid and a.rq='200007' and b.rq='200007' and c.rq='200007' and d.rq='200007' and f.rq='200007' and g.rq='200007'
From hishtxftb a,
hishtfwtb b ,
(select fhid,sum(feiyong) feiyong from hismqtb group by fhid) c,
(select fhid,sum(hj) hj from hisdhtb group by fhid) d ,
(select fhid,sum(feiyong) feiyong from hisdbtb group by fhid) f ,
(select fhid,sum(g.psf+g.fy) shb from hisshbtb group by fhid) g
where
a.xh=b.xh and b.fhid=c.fhid and b.fhid=d.fhid and b.fhid=f.fhid and b.fhid=g.fhid and a.rq='200007' and b.rq='200007' and c.rq='200007' and d.rq='200007' and f.rq='200007' and g.rq='200007'
From hishtxftb a,
hishtfwtb b ,
(select fhid,sum(feiyong) feiyong from hismqtb group by fhid) c,
(select fhid,sum(hj) hj from hisdhtb group by fhid) d ,
(select fhid,sum(feiyong) feiyong from hisdbtb group by fhid) f ,
(select fhid,sum(g.psf+g.fy) shb from hisshbtb group by fhid) g
where
a.xh=b.xh and b.fhid=c.fhid and b.fhid=d.fhid and b.fhid=f.fhid and b.fhid=g.fhid and a.rq='200007' and b.rq='200007' and c.rq='200007' and d.rq='200007' and f.rq='200007' and g.rq='200007'
group by a.xh
?????
select a.xh,sum(c.feiyong) as mq,sum(d.hj) as dh,sum(f.feiyong) as db ,sum(g.psf+g.fy) as shb
From hishtxftb a,
left join hishtfwtb b on a.xh = b.xh and a.rq = b.rq
left join hismqtb c on b.fhid = c.fhid and b.rq = c.rq
left join hisdhtb d on b.fhid = d.fhid and b.rq = d.rq
left join hisdbtb f on b.fhid = f.fhid and b.rq = f.rq
left join hisshbtb g on b.fhid = g.fhid and b.rq = g.rq
where a.rq='200007'
group by a.xh