select or7.structname,
round(sum(tt.bqfh12) / 10000, 2) bqfh,
round(sum(tt.sqkc12) / 10000, 2) sqkc,
round(sum(tt.bqkc12) / 10000, 2) bqkc,
round(sum(tt.khxl2) / 10000, 2) khxl
from organization or7,
(select substr(o.vorder,
1,
(select max(length(or6.vorder)) as vorder
from organization or6
where or6.parentid = 2)) as vorder,
sum(t.bqfh1) bqfh12,
sum(t.sqkc1) sqkc12,
sum(t.bqkc1) bqkc12,
sum(t.khxl) khxl2
from (select tmp.struct_id,
nvl(sum(tmp.bqfh), 0) bqfh1,
nvl(sum(tmp.sqkc), 0) sqkc1,
nvl(sum(tmp.bqkc), 0) bqkc1,
nvl(decode(sum(tmp.bqkc),
null,
sum(tmp.bqfh) + nvl(sum(tmp.sqkc), 0),
sum(tmp.bqfh) + nvl(sum(tmp.sqkc), 0) -
sum(tmp.bqkc)),
'0') khxl
from (select ue.struct_id,
ue.cust_id,
ues.productid,
0 bqfh,
case
when ue.stop_time =
to_date('2011-12-12', 'yyyy-MM-dd') then
sum(ues.count * p.price)
end sqkc,
case
when ue.stop_time =
to_date('2011-12-25', 'yyyy-MM-dd') then
sum(ues.count * p.price)
end bqkc
from up_endkc ue, up_endkc_sub ues, product p
where ue.id = ues.orderid
and ues.productid = p.productid
and ue.del_sign = 0
and ues.isusing = 0
and ue.stop_time in
(to_date('2011-12-12', 'yyyy-MM-dd'),
to_date('2011-12-25', 'yyyy-MM-dd'))
and ue.struct_id in
(select structid
from organization o
where o.vorder like
(select vorder
from organization oo
where oo.structid = 2) || '%')
group by ue.struct_id,
ue.stop_time,
ue.cust_id,
ues.productid
union all
select fp.org_id struct_id,
fp.custid cust_id,
fp.productid,
sum(fp.zk_nofax_jine + fp.zfax) bqfh,
0 sqkc,
0 bqkc
from fp
where fp.kprq > '20111212'
and fp.kprq <= '20111225'
and fp.isusing = 0
and fp.org_id in
(select structid
from organization o
where o.vorder like
(select vorder
from organization oo
where oo.structid = 2) || '%')
and fp.custid in
(select ue.cust_id
from up_endkc ue
where ue.del_sign = 0
and ue.stop_time in
(to_date('2011-12-12', 'yyyy-MM-dd'),
to_date('2011-12-25', 'yyyy-MM-dd')))
and fp.productid in
(select ues.productid
from up_endkc ue, up_endkc_sub ues
where ue.id = ues.orderid
and ue.del_sign = 0
and ues.isusing = 0
and ue.stop_time in
(to_date('2011-12-12', 'yyyy-MM-dd'),
to_date('2011-12-25', 'yyyy-MM-dd')))
group by fp.org_id, fp.custid, fp.productid) tmp,
product p
where tmp.productid = p.productid
group by tmp.struct_id) t,
organization o
where t.struct_id = o.structid
group by vorder) tt
where tt.vorder = or7.vorder
group by or7.structname
order by khxl
这是sql语句,两段分别执行都很快,和在一起执行就慢,而且就12月慢,11月时两段一起执行就很快