这个查询有没有优化的余地?

[复制链接]
查看11 | 回复6 | 2015-3-6 11:57:31 | 显示全部楼层 |阅读模式
update c_tpa_sts_cell_ne a set dropcall_rate_delta=(dropcall_rate)/(select distinct decode(dropcall_rate,0,1,dropcall_rate) from c_tpa_sts_cell_ne where scan_start_time=to_date('2009-10-11 14:0:0','yyyy-mm-dd hh24.mi:ss')-1/24 and int_id=a.int_id and int_id is not null)-1
where scan_start_time='2009-10-11 14:0:0';
update c_tpa_sts_cell_ne a set dropcall_delta=(dropcall)/(select distinct decode(dropcall,0,1,dropcall) from c_tpa_sts_cell_ne where scan_start_time=to_date('2009-10-11 14:0:0','yyyy-mm-dd hh24.mi:ss')-1/24 and int_id=a.int_id and int_id is not null)-1
where scan_start_time='2009-10-11 14:0:0';

update c_tpa_sts_cell_ne a set block_rate_delta=(block_rate)/(select distinct decode(block_rate,0,1,block_rate) from c_tpa_sts_cell_ne where scan_start_time=to_date('2009-10-11 14:0:0','yyyy-mm-dd hh24.mi:ss')-1/24 and int_id=a.int_id and int_id is not null)-1
where scan_start_time='2009-10-11 14:0:0';
update c_tpa_sts_cell_ne a set succ_rate_delta=(succ_rate)/(select distinct decode(succ_rate,0,1,succ_rate) from c_tpa_sts_cell_ne where scan_start_time=to_date('2009-10-11 14:0:0','yyyy-mm-dd hh24.mi:ss')-1/24 and int_id=a.int_id and int_id is not null)-1
where scan_start_time='2009-10-11 14:0:0';
就是利用这个表和上个小时的增量比率来得到本小时的值
回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
能不能把这几个sql整合到一个?
回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
可以合成一条sql,最简单的方式就是
update tbl set (col1,col2,col3...)=(select .... from tbl2....) where .......
回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
int_id这个id是主键吗?
回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
上面的弄错了
select distinct decode(block_rate,0,1,block_rate) from c_tpa_sts_cell_ne where scan_start_time=to_date('2009-10-11 14:0:0','yyyy-mm-dd hh24.mi:ss')-1/24 and int_id=a.int_id and int_id is not null
这个查询不加distinct的时候可能抽出来多条数据吗?
回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
条件不一样的原帖由 junsansi 于 2009-10-11 17:31 发表
可以合成一条sql,最简单的方式就是
update tbl set (col1,col2,col3...)=(select .... from tbl2....) where .......

回复

使用道具 举报

千问 | 2015-3-6 11:57:31 | 显示全部楼层
对主表的约束条件都是一样的,可尝试:
update a set col1=,col2=,col3= where scan_start_time='2009-10-11 14:0:0';
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行