UPDATE sum(100分)

  • 主题发起人 主题发起人 wangqinyun2000
  • 开始时间 开始时间
W

wangqinyun2000

Unregistered / Unconfirmed
GUEST, unregistred user!
表1CWBDC<br>字段<br>CGDH &nbsp; LH &nbsp; &nbsp; JHSL &nbsp;<br>X1 &nbsp; &nbsp; Y1 &nbsp; &nbsp; &nbsp;0<br>X9 &nbsp; &nbsp; Y3 &nbsp; &nbsp; &nbsp;0<br>表2#JHMXTEMP1<br>字段<br>CGDH &nbsp; BH &nbsp; &nbsp; JHSL &nbsp;<br>X1 &nbsp; &nbsp; Y1 &nbsp; &nbsp; &nbsp;23<br>X1 &nbsp; &nbsp; Y1 &nbsp; &nbsp; &nbsp;40<br>X9 &nbsp; &nbsp; Y3 &nbsp; &nbsp; &nbsp;90<br>X9 &nbsp; &nbsp; Y3 &nbsp; &nbsp; &nbsp;100<br><br>表1CWBDC.JHSL等于表2#JHMXTEMP1.JHSL的和,条件是1CWBDC.CGDH=表2#JHMXTEMP1.CGDH AND CWBDC.LH =#JHMXTEMP1.BH<br><br><br>最终表1CWBDC结果为:<br>CGDH &nbsp; LH &nbsp; &nbsp; JHSL &nbsp;<br>X1 &nbsp; &nbsp; Y1 &nbsp; &nbsp; &nbsp;63<br>X9 &nbsp; &nbsp; Y3 &nbsp; &nbsp; &nbsp;190<br><br><br>ADOQ1.SQL.Add('update CWBDC SET CWBDC.JHSL=(select SUM(#JHMXTEMP1.JHSL) FROM #JHMXTEMP1,CWBDC WHERE #JHMXTEMP1.CGDH=CWBDC.CGDH AND #JHMXTEMP1.BH =CWBDC.LH group by #JHMXTEMP1.CGDH,#JHMXTEMP1.BH)');<br><br>上面代码得为不到正确的结果,帮忙看看
 
用触发器做更容易一些
 
update CWBDC set JHSL=a.aaa <br>from (select sum(JHSL) as aaa,CGDH,BH from JHMXTEMP1 group by CGDH,BH) a ,<br>&nbsp;CWBDC where #JHMXTEMP1.CGDH=CWBDC.CGDH AND #JHMXTEMP1.BH =CWBDC.LH
 
后退
顶部