日期:2014-05-19  浏览次数:20559 次

求教3条库存更新的SQL语句
更新库存的语句如下:

/*1*/
update   mis_sp_kc  
set   mis_sp_kc.sl_qm   =mis_sp_kc.sl_qm   +   dj.sl   ,  
mis_sp_kc.je_qm   =mis_sp_kc.je_qm   +   dj.je_cb   ,  
mis_sp_kc.sl_in   =mis_sp_kc.sl_in   +   dj.sl   ,  
mis_sp_kc.je_in   =mis_sp_kc.je_in   +  
dj.je_cb   from  
(select   bm_sp   ,   bm_ck   ,   sum   (sl)   sl   ,   sum   (je)   je_cb   from   jxc_gh_2  
where   jxc_gh_2.dh   = 'AK20070620_007 '     group   by   bm_sp,bm_ck)
  dj  
where   dj.bm_sp   =mis_sp_kc.bm_sp   and   dj.bm_ck   =mis_sp_kc.bm_ck  
/*上面这条语句是更新查询出来的数据到   mis_sp_kc表,但是那个   dj   是什么意思?*/


/*2*/
insert   into   mis_sp_kc  
(jxc_yyyymm   ,bm_ck,bm_sp,sl_in,je_in,   sl_qm   ,   je_qm   )  
select   '200706 '   ,bm_ck,   bm_sp,sl,je_cb,sl,   je_cb   from  
(   select   bm_sp,bm_ck,sum(sl)sl,sum   (je_cb)   je_cb   from  
jxc_gh_2  
where   dh   = 'AK20070620_007 '   group   by   bm_sp   ,   bm_ck   )   dj,jxc_bm_sp  
where   dj.bm_sp=jxc_bm_sp.bm   and   jxc_bm_sp.kcfs   =1   and   dj.bm_ck+dj.bm_sp   not   in  
(select   bm_ck   +   bm_sp   from   mis_sp_kc)  

/*3*/
update   mis_sp_kc   set   dj_cb   =je_qm   /   sl_qm   where   sl_qm   <>   0   and   bm_ck   +   bm_sp  
in   (   select     bm_ck   +   bm_sp   from   jxc_gh_2   where   jxc_yyyymm   = '200706 '   and   dh   = 'AK20070620_007 '   )  


求教这三条语句的含义

------解决方案--------------------
/*上面这条语句是更新查询出来的数据到 mis_sp_kc表,但是那个 dj 是什么意思?*/
-------------
dj是別名,你用別的名字也可以。
------解决方案--------------------
1 dj是別名,FROM中的子查询必须有个别名

2
3
楼住需要了解下子查询,看看联机帮助