高分求优化SQL语句(200分)

  • 主题发起人 主题发起人 jetcoyuan
  • 开始时间 开始时间
J

jetcoyuan

Unregistered / Unconfirmed
GUEST, unregistred user!
select count(*) from dic_mat_type a ,pro_fin_inventory b,dic_um c,dic_wh_type d
where a.code(+) = b.mat_type and c.code(+)=b.unit and d.code= b.wh_code
and a.role_no in (select role_no from ctl_user_right where userid ='0011')
and d.code in (select wh_code from dic_region_inv_role where role_no
in (select role_no from ctl_user_right where userid ='0011'))

执行上述语句10000条记录要将近1分钟,如何优化
 
改用临时表或者用存储过程
 
oracle:
select count(rowid) form ....................
 
将where 条件中的in中的(select。。。。)去掉。那个条件放在第一个中.如
select count(*) from dic_mat_type a ,pro_fin_inventory b,dic_um c,dic_wh_type d,ctl_user_right e,dic_region_inv_role f
where a.code(+) = b.mat_type and c.code(+)=b.unit and d.code= b.wh_code and (e. =) and (userid ='0011')
and (a.roleid=e.roleid)...........最好将这几个表的关系图给我!!!
 
用左链接或右链接!
 
用存储过程
 
改为存储过程
 
不曉得你要的是什么樣的結果,下面的只是做個參考,如果用得著左連接的話,建義用一下左連接
select
count(*)
from
dic_mat_type a ,
pro_fin_inventory b,
dic_um c,
dic_wh_type d,
(select role_no from ctl_user_right where userid ='0011') e,
(select wh_code,role_no from dic_region_inv_role) f
where
a.code(+) = b.mat_type
and c.code(+)=b.unit
and d.code= b.wh_code
and a.role_no = e.role_no
and e.role_no = f.role_no
and d.code = f.wh_no
 
请给出具体语句
 
要想更快,最好用临时表或存储过程
 
可用存储过程实现:
select count(*)
from (select Tole_no from dic_mat_type
where role_no in
(select role_no from ctl_user_right where userid ='0011')) as a ,
pro_fin_inventory b,
dic_um c,
(select code from dic_wh_type
where code in
(select wh_code from dic_region_inv_role where role_no
in (select role_no from ctl_user_right where userid ='0011'))) as d
where a.code(+) = b.mat_type
and c.code(+)=b.unit
and d.code= b.wh_code
 
接受答案了.
 
后退
顶部