表1
Book_tbl
BookID BookName SaleAmount
1         aaa      10
2         bbb      20
3         ccc      30
4         ddd      32
5         eee      12
6         fff      11Shoppingcart_tbl
CartID  BookID   Qunatity
001      2        10
001      3        20
001      4        30
002      2        11
002      4        21
002      5        31我想把CartID为001中的书的数量加到Book_tbl中
即要得到的结果是
Book_tbl
BookID BookName SaleAmount
1         aaa      10
2         bbb      20+10
3         ccc      30+20
4         ddd      32+30
5         eee      12
6         fff      11我写的是
update Book_tlb set SaleAmount=SaleAmount+(select Quantity from Shoppingcart_tbl where CartID='001') where Book_tbl.BookID=Shoppingcart_tbl.BookID
但是不行
请问哪里不对?
改怎么写?

解决方案 »

  1.   

    Update Book_tbl Set SaleAmount=SaleAmount + (Select Sum(Shoppincart_tbl.Quantity) From Shoppincart_tbl Inner Join Book_tbl On Book_tbl.BookID=Shoppincart_tbl.BookID)我也不知道行不行,试一下吧
      

  2.   


    update   Book_tlb   set   SaleAmount=SaleAmount+Quantity  from  Shoppingcart_tbl     where   Book_tbl.BookID=Shoppingcart_tbl.BookID and Shoppingcart_tbl='001'
      

  3.   

    回:tabbycat
    我不需要求和
    ------------------------------------------------------------
    回:漆黑的夜谢谢 你的是对的 但是,为什么 Quantity前面没有select?