oracle union后分组慢,数据量庞大(25万条),要运算加分组,反应极慢,如何优化啊求解,sql比较多...

select rownum,

collieryname,

transunitname,

collieryid,

transunitid,

plannum,

truenum,

decode

(substr(arrive, 1, 1), '.', '0' || arrive, arrive) arrive

from (select collieryname,

transunitname,

collieryid,

transunitid,

plannum,

truenum,

arrive

from (select thr2.collieryname,

thr3.transunitname,

thr1.collieryid,

thr1.transunitid,

thr1.plannum,

thr1.truenum,

round(thr1.truenum / thr1.plannum, 3) * 100 arrive

from (select distinct collieryid,

transunitid,

plannum,

truenum

from (select sec1.collieryid,

to_number(sec1.transunitid) transunitid,

plannum,

truenum

from (select t2.collieryid,

to_number(t1.TRANSUNIT) transunitid,

sum(t1.TCOUNT) plannum

from (select TRANSUNIT, TCOUNT, PLANID

from HNDFBPS_FUEL.T_TRUCKBILL

where TDATE >= '2013-01-25'

and TDATE <= '2013-01-25') t1,

HNDFBPS_FUEL.t_truckcoalplan t2,

HNDFBPS_fuel.T_TRUCKATTEMPPLAN t3

where t1.PLANID = t3.id

and t3.TRUCKCOALPLANID = t2.id

group by t2.collieryid, t1.TRANSUNIT) sec1,

(select count(id) truenum,

collieryid,

transunitid

from (select collieryid,

t.id,

(select transunitid

from HNDFBPS_FUEL.t_truckbelong

where truckid = t.truckid

and substr

(tosamtime,

1,

10) >=

starttime

and substr(tosamtime,

1,

10) <=

stoptime) transunitid

from HNDFBPS_FUEL.t_truckenter t

where SUBSTR(t.tosamtime, 1, 10) >=

'2013-01-25'

and SUBSTR(t.tosamtime, 1, 10) <=

'2013-01-25'

and t.eweighttime is not null) t1

group by t1.collieryid, t1.transunitid) sec2

where sec1.collieryid = sec2.collieryid(+)

and sec1.transunitid = sec2.transunitid(+)

union all

select sec2.collieryid,

sec2.transunitid,

plannum,

truenum

from (select t2.collieryid,

to_number(t1.TRANSUNIT) transunitid,

sum(t1.TCOUNT) plannum

from (select TRANSUNIT, TCOUNT, PLANID

from HNDFBPS_FUEL.T_TRUCKBILL

where TDATE >= '2013-01-25'

and TDATE <= '2013-01-25') t1,

HNDFBPS_FUEL.t_truckcoalplan t2,

HNDFBPS_fuel.T_TRUCKATTEMPPLAN t3

where t1.PLANID = t3.id

and t3.TRUCKCOALPLANID = t2.id

group by t2.collieryid, t1.TRANSUNIT) sec1,

(select count(id) truenum,

collieryid,

transunitid

from (select collieryid,

t.id,

(select transunitid

from HNDFBPS_FUEL.t_truckbelong

where truckid = t.truckid

and substr(tosamtime,

1,

10) >=

starttime

and substr(tosamtime,

1,

10) <=

stoptime) transunitid

from HNDFBPS_FUEL.t_truckenterover t

where SUBSTR(t.tosamtime, 1, 10) >=

'2013-01-25'

and SUBSTR(t.tosamtime, 1, 10) <=

'2013-01-25'

and t.eweighttime is not null) t1

group by t1.collieryid, t1.transunitid) sec2

where sec1.collieryid(+) = sec2.collieryid

and sec1.transunitid(+) = sec2.transunitid)) thr1,

HNDFBPS_FUEL.t_colliery thr2,

HNDFBPS_FUEL.t_transunit thr3

where thr1.collieryid = thr2.id

and thr1.transunitid = thr3.id

union all

select thr2.collieryname || ':合计' ncollieryname,

'' transunitname,

collieryid,

transunitid,

nplannum,

ntruenum,

arrive

from (select collieryid,

0 transunitid,

sum(plannum) nplannum,

sum(truenum) ntruenum,

round(sum(truenum) / sum(plannum), 3) * 100 arrive

from (select distinct collieryid,

transunitid,

plannum,

truenum

from (select sec1.collieryid,

to_number(sec1.transunitid) transunitid,

plannum,

truenum

from (select t2.collieryid,

to_number(t1.TRANSUNIT) transunitid,

sum(t1.TCOUNT) plannum

from (select TRANSUNIT,

TCOUNT,

PLANID

from HNDFBPS_FUEL.T_TRUCKBILL

where TDATE >=

'2013-01-25'

and TDATE <=

'2013-01-25') t1,

HNDFBPS_FUEL.t_truckcoalplan t2,

HNDFBPS_fuel.T_TRUCKATTEMPPLAN t3

where t1.PLANID = t3.id

and t3.TRUCKCOALPLANID = t2.id

group by t2.collieryid,

t1.TRANSUNIT) sec1,

(select count(id) truenum,

collieryid,

transunitid

from (select collieryid,

t.id,

(select transunitid

from HNDFBPS_FUEL.t_truckbelong

where truckid =

t.truckid

and substr(tosamtime,

1,

10) >=

starttime

and substr(tosamtime,

1,

10) <=

stoptime) transunitid

from HNDFBPS_FUEL.t_truckenter t

where SUBSTR(t.tosamtime,

1,

10) >=

'2013-01-25'

and SUBSTR(t.tosamtime,

1,

10) <=

'2013-01-25'

and t.eweighttime is not null) t1

group by t1.collieryid,

t1.transunitid) sec2

where sec1.collieryid =

sec2.collieryid(+)

and sec1.transunitid =

sec2.transunitid(+)

union all

select sec2.collieryid,

sec2.transunitid,

plannum,

truenum

from (select t2.collieryid,

to_number(t1.TRANSUNIT) transunitid,

sum(t1.TCOUNT) plannum

from (select TRANSUNIT,

TCOUNT,

PLANID

from HNDFBPS_FUEL.T_TRUCKBILL

where TDATE >=

'2013-01-25'

and TDATE <=

'2013-01-25') t1,

HNDFBPS_FUEL.t_truckcoalplan t2,

HNDFBPS_fuel.T_TRUCKATTEMPPLAN t3

where t1.PLANID = t3.id

and t3.TRUCKCOALPLANID = t2.id

group by t2.collieryid,

t1.TRANSUNIT) sec1,

(select count(id) truenum,

collieryid,

transunitid

from (select collieryid,

t.id,

(select transunitid

from HNDFBPS_FUEL.t_truckbelong

where truckid =

t.truckid

and substr(tosamtime,

1,

10) >=

starttime

and substr(tosamtime,

1,

10) <=

stoptime) transunitid

from HNDFBPS_FUEL.t_truckenterover t

where SUBSTR(t.tosamtime,

1,

10) >=

'2013-01-25'

and SUBSTR(t.tosamtime,

1,

10) <=

'2013-01-25'

and t.eweighttime is not null) t1

group by t1.collieryid,

t1.transunitid) sec2

where sec1.collieryid(+) =

sec2.collieryid

and sec1.transunitid(+) =

sec2.transunitid)) tem1

group by tem1.collieryid) thr1,

HNDFBPS_FUEL.t_colliery thr2

where thr1.collieryid = thr2.id

union all

select '总合计' ncollieryname,

'' transunitname,

collieryid,

transunitid,

nplannum,

ntruenum,

arrive

from (select 0 collieryid,

0 transunitid,

sum(plannum) nplannum,

sum(truenum) ntruenum,

round(sum(truenum) / sum(plannum), 3) * 100 arrive

from (select distinct collieryid,

transunitid,

plannum,

truenum

from (select sec1.collieryid,

to_number(sec1.transunitid) transunitid,

plannum,

truenum

from (select t2.collieryid,

to_number(t1.TRANSUNIT) transunitid,

sum(t1.TCOUNT) plannum

from (select TRANSUNIT,

TCOUNT,

PLANID

from HNDFBPS_FUEL.T_TRUCKBILL

where TDATE >=

'2013-01-25'

and TDATE <=

'2013-01-25') t1,

HNDFBPS_FUEL.t_truckcoalplan t2,

HNDFBPS_fuel.T_TRUCKATTEMPPLAN t3

where t1.PLANID = t3.id

and t3.TRUCKCOALPLANID = t2.id

group by t2.collieryid,

t1.TRANSUNIT) sec1,

(select count(id) truenum,

collieryid,

transunitid

from (select collieryid,

t.id,

(select transunitid

from HNDFBPS_FUEL.t_truckbelong

where truckid =

t.truckid

and substr(tosamtime,

1,

10) >=

starttime

and substr(tosamtime,

1,

10) <=

stoptime) transunitid

from HNDFBPS_FUEL.t_truckenter t

where SUBSTR(t.tosamtime,

1,

10) >=

'2013-01-25'

and SUBSTR(t.tosamtime,

1,

10) <=

'2013-01-25'

and t.eweighttime is not null) t1

group by t1.collieryid,

t1.transunitid) sec2

where sec1.collieryid =

sec2.collieryid(+)

and sec1.transunitid =

sec2.transunitid(+)

union all

select sec2.collieryid,

sec2.transunitid,

plannum,

truenum

from (select t2.collieryid,

to_number(t1.TRANSUNIT) transunitid,

sum(t1.TCOUNT) plannum

from (select TRANSUNIT,

TCOUNT,

PLANID

from HNDFBPS_FUEL.T_TRUCKBILL

where TDATE >=

'2013-01-25'

and TDATE <=

'2013-01-25') t1,

HNDFBPS_FUEL.t_truckcoalplan t2,

HNDFBPS_fuel.T_TRUCKATTEMPPLAN t3

where t1.PLANID = t3.id

and t3.TRUCKCOALPLANID = t2.id

group by t2.collieryid,

t1.TRANSUNIT) sec1,

(select count(id) truenum,

collieryid,

transunitid

from (select collieryid,

t.id,

(select transunitid

from HNDFBPS_FUEL.t_truckbelong

where truckid =

t.truckid

and substr(tosamtime,

1,

10) >=

starttime

and substr(tosamtime,

1,

10) <=

stoptime) transunitid

from HNDFBPS_FUEL.t_truckenterover t

where SUBSTR(t.tosamtime,

1,

10) >=

'2013-01-25'

and SUBSTR(t.tosamtime,

1,

10) <=

'2013-01-25'

and t.eweighttime is not null) t1

group by t1.collieryid,

t1.transunitid) sec2

where sec1.collieryid(+) =

sec2.collieryid

and sec1.transunitid(+) =

sec2.transunitid)) sec1) thr1)

order by collieryname)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值