oracle跨时间段查询语句,同一段查询语句时间不同有的执行很快,有的半天出不来结果...

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月时两段一起执行就很快

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值