MYSQL更新和SUM

时间:2014-12-04 16:51:09

标签: mysql select sql-update sum inner-join

我试着像这样做一些想法

UPDATE BA C
INNER JOIN
(
    SELECT SUM(`Amount`) AS `LSC`,`To` FROM `Trans`
) A ON C.`UserID` = A.`To`

INNER JOIN
(
    SELECT SUM(`Amount`) AS `LSC`,`From` FROM `Trans`
) B ON C.`UserID` = B.`From`

SET `Bal` = A.`LSC` - B.`LSC`;

这不是workink:\ 当我只做一个内部联接并运行查询两次一次到A和第二次是它的工作,但我想在一个查询中做... ...

UPDATE BA C
INNER JOIN
(
    SELECT SUM(`Amount`) AS `LSC`,`To` FROM `Trans`
) A ON C.`UserID` = A.`To`

SET `Bal` = A.`LSC`; // Work 

0 个答案:

没有答案