select *
from (select P.*,
rownum rw,
min(销售金额) over(partition by 网点编号) as 最低销售额,
max(销售金额) over(partition by 网点编号) as 最高销售额,
avg(销售金额) over(partition by 网点编号) as 本点平均销售量
from (select A.网点编号,
A.地区,
A.时段,
A.销售票数,
A.销售金额,
A.单票销量,
D.地市平均,
B.全省平均,
C.历史最高销售额,
C.历史最低销售额
from (select sum(sell_count) 销售票数,
sum(sell_amount) 销售金额,
decode(sum(sell_count),
0,
0,
ROUND(sum(sell_amount) / sum(sell_count),
2)) 单票销量,
A.Terminal_Sell_Id 网点编号,
to_char(A.open_result_time, 'yyyy-mm-dd') 时段,
C.Area_Name 地区
from terminal_sell A,
SALES_OUTLETS_INFO B,
area C,
playtype D
where D.PLAYTYPE_ID(+) = A.Lottery_Type
and C.AREA_ID(+) = B.Area_Id
and B.Sell_Id(+) = A.Terminal_Sell_Id
and A.Lottery_Type in ('04',
'05',
'35',
'350133',
'37',
'38',
'85',
'850001',
'88',
'90',
'900129',
'93',
'94',
'96',
'98')
and A.OPEN_RESULT_TIME >=
to_date('2008-01-01', 'yyyy-mm-dd')
and A.OPEN_RESULT_TIME <=
to_date('2008-2-22', 'yyyy-mm-dd')
and A.Terminal_Sell_Id like '02219'
group by A.Terminal_Sell_Id,
C.Area_Name,
to_char(A.open_result_time, 'yyyy-mm-dd')) A,
(select ROUND(avg(sell_amount), 2) 全省平均,
to_char(A.open_result_time, 'yyyy-mm-dd') 时段
from terminal_sell A,
SALES_OUTLETS_INFO B,
playtype D
where D.PLAYTYPE_ID(+) = A.Lottery_Type
and B.Sell_Id(+) = A.Terminal_Sell_Id
and A.Lottery_Type in ('04',
'05',
'35',
'350133',
'37',
'38',
'85',
'850001',
'88',
'90',
'900129',
'93',
'94',
'96',
'98')
and A.OPEN_RESULT_TIME >=
to_date('2008-01-01', 'yyyy-mm-dd')
and A.OPEN_RESULT_TIME <=
to_date('2008-2-22', 'yyyy-mm-dd')
group by 1, to_char(A.open_result_time, 'yyyy-mm-dd')) B,
(select ROUND(avg(sell_amount), 2) 地市平均,
C.area_name 地区,
to_char(A.open_result_time, 'yyyy-mm-dd') 时段
from terminal_sell A,
SALES_OUTLETS_INFO B,
Area C,
playtype D
where D.PLAYTYPE_ID(+) = A.Lottery_Type
and B.Sell_Id(+) = A.Terminal_Sell_Id
and C.Area_id(+)= B.Area_Id
and A.Lottery_Type in ('04',
'05',
'35',
'350133',
'37',
'38',
'85',
'850001',
'88',
'90',
'900129',
'93',
'94',
'96',
'98')
and A.OPEN_RESULT_TIME >=
to_date('2008-01-01', 'yyyy-mm-dd')
and A.OPEN_RESULT_TIME <=
to_date('2008-2-22', 'yyyy-mm-dd')
group by C.area_name, to_char(A.open_result_time, 'yyyy-mm-dd')) D,
(select max(销假售额) 历史最高销售额,
min(销假售额) 历史最低销售额,
网点编号
from (select sum(A.sell_amount) 销假售额,
to_char(A.open_result_time, 'yyyy-mm-dd') 时段,
a.terminal_sell_id 网点编号
from terminal_sell a, playtype D
where D.PLAYTYPE_ID(+) = A.Lottery_Type
group by a.terminal_sell_id,
to_char(A.open_result_time,
'yyyy-mm-dd'))
group by 网点编号) C
where 1 = 1
and C.网点编号 = A.网点编号
and B.时段 = A.时段
and D.地区=A.地区
and D.时段=A.时段
) P
)上面这语句是正常了,但速度非常慢,请问怎么优化或重写上面sql语句
from (select P.*,
rownum rw,
min(销售金额) over(partition by 网点编号) as 最低销售额,
max(销售金额) over(partition by 网点编号) as 最高销售额,
avg(销售金额) over(partition by 网点编号) as 本点平均销售量
from (select A.网点编号,
A.地区,
A.时段,
A.销售票数,
A.销售金额,
A.单票销量,
D.地市平均,
B.全省平均,
C.历史最高销售额,
C.历史最低销售额
from (select sum(sell_count) 销售票数,
sum(sell_amount) 销售金额,
decode(sum(sell_count),
0,
0,
ROUND(sum(sell_amount) / sum(sell_count),
2)) 单票销量,
A.Terminal_Sell_Id 网点编号,
to_char(A.open_result_time, 'yyyy-mm-dd') 时段,
C.Area_Name 地区
from terminal_sell A,
SALES_OUTLETS_INFO B,
area C,
playtype D
where D.PLAYTYPE_ID(+) = A.Lottery_Type
and C.AREA_ID(+) = B.Area_Id
and B.Sell_Id(+) = A.Terminal_Sell_Id
and A.Lottery_Type in ('04',
'05',
'35',
'350133',
'37',
'38',
'85',
'850001',
'88',
'90',
'900129',
'93',
'94',
'96',
'98')
and A.OPEN_RESULT_TIME >=
to_date('2008-01-01', 'yyyy-mm-dd')
and A.OPEN_RESULT_TIME <=
to_date('2008-2-22', 'yyyy-mm-dd')
and A.Terminal_Sell_Id like '02219'
group by A.Terminal_Sell_Id,
C.Area_Name,
to_char(A.open_result_time, 'yyyy-mm-dd')) A,
(select ROUND(avg(sell_amount), 2) 全省平均,
to_char(A.open_result_time, 'yyyy-mm-dd') 时段
from terminal_sell A,
SALES_OUTLETS_INFO B,
playtype D
where D.PLAYTYPE_ID(+) = A.Lottery_Type
and B.Sell_Id(+) = A.Terminal_Sell_Id
and A.Lottery_Type in ('04',
'05',
'35',
'350133',
'37',
'38',
'85',
'850001',
'88',
'90',
'900129',
'93',
'94',
'96',
'98')
and A.OPEN_RESULT_TIME >=
to_date('2008-01-01', 'yyyy-mm-dd')
and A.OPEN_RESULT_TIME <=
to_date('2008-2-22', 'yyyy-mm-dd')
group by 1, to_char(A.open_result_time, 'yyyy-mm-dd')) B,
(select ROUND(avg(sell_amount), 2) 地市平均,
C.area_name 地区,
to_char(A.open_result_time, 'yyyy-mm-dd') 时段
from terminal_sell A,
SALES_OUTLETS_INFO B,
Area C,
playtype D
where D.PLAYTYPE_ID(+) = A.Lottery_Type
and B.Sell_Id(+) = A.Terminal_Sell_Id
and C.Area_id(+)= B.Area_Id
and A.Lottery_Type in ('04',
'05',
'35',
'350133',
'37',
'38',
'85',
'850001',
'88',
'90',
'900129',
'93',
'94',
'96',
'98')
and A.OPEN_RESULT_TIME >=
to_date('2008-01-01', 'yyyy-mm-dd')
and A.OPEN_RESULT_TIME <=
to_date('2008-2-22', 'yyyy-mm-dd')
group by C.area_name, to_char(A.open_result_time, 'yyyy-mm-dd')) D,
(select max(销假售额) 历史最高销售额,
min(销假售额) 历史最低销售额,
网点编号
from (select sum(A.sell_amount) 销假售额,
to_char(A.open_result_time, 'yyyy-mm-dd') 时段,
a.terminal_sell_id 网点编号
from terminal_sell a, playtype D
where D.PLAYTYPE_ID(+) = A.Lottery_Type
group by a.terminal_sell_id,
to_char(A.open_result_time,
'yyyy-mm-dd'))
group by 网点编号) C
where 1 = 1
and C.网点编号 = A.网点编号
and B.时段 = A.时段
and D.地区=A.地区
and D.时段=A.时段
) P
)上面这语句是正常了,但速度非常慢,请问怎么优化或重写上面sql语句
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货