更新表(多表相关联)

update f_shortforest forest
   
set forest.forestquantity = (select (decode(sum(detail.quantity),
                                               
null,
                                               
0,
                                               
sum(detail.quantity)) * 0.6 +
                                       decode(forest.forestquantity,
                                               
null,
                                               
0,
                                               forest.forestquantity) 
* 0.4)
                                  
FROM d_salerplan@tpo       master,
                                       d_salerplandetail
@tpo detail
                                 
where master.sorderid = detail.sorderid
                                   
and forest.estimateyear =
                                       substr(master.ordermonth, 
14)
                                   
and forest.month =
                                       substr(master.ordermonth, 
52)
                                   
and forest.productid = detail.productid
                                 
group by detail.productid)
where exists(select detail.quantity
                                  
FROM d_salerplan@tpo       master,
                                       d_salerplandetail
@tpo detail
                                 
where master.sorderid = detail.sorderid
                                   
and forest.estimateyear =
                                       substr(master.ordermonth, 
14)
                                   
and forest.month =
                                       substr(master.ordermonth, 
52)
                                   
and forest.productid = detail.productid);
posted on 2006-06-16 15:47  老狐狸  阅读(234)  评论(0)    收藏  举报