update table1 set amount=(select (quan*price) as amount from table1 where bindid=218214) where bindid=218214
表中的bindid对应四条数据,四条数据的数量和单价求和得出金额,再更新数据,怎总是单行子查询返回多行,请问这个问题有没有什么解决的好办法啊?

解决方案 »

  1.   


    update table1 t
       set amount = (select amount
                       from (select sum(quan * price) as amount, bindid
                               from table1
                              where bindid = 218214
                              group by bindid) a
                      where a.bindid = b.bindid)
      

  2.   


    ------这样。。
    update table1 t
       set t.amount = (select a.amount
                         from (select sum(quan * price) as amount, bindid
                                 from table1
                                where bindid = 218214
                                group by bindid) a
                        where a.bindid = t.bindid)
     where t.bindid = 218214
      

  3.   


    ------这样。。
    update table1 t
       set t.amount = (select a.amount
                         from (select sum(quan * price) as amount, bindid
                                 from table1
                                where bindid = 218214
                                group by bindid) a
                        where a.bindid = t.bindid)
     where t.bindid = 218214
      

  4.   


    update table1 set amount=
      (select sum(quan*price) from table1 where bindid=218214 group by bindid)
    where bindid=218214