首页 > 解决方案 > 将我获得金额的子查询绑定到我的主查询

问题描述

我需要帮助将我的子查询绑定到我的主查询中。fundID 是我需要绑定的字段。

这是我为每个基金添加剩余余额(负值)而编写的语句,但子查询返回多个值。有没有办法可以将检索金额的子查询中的fundID绑定到主查询的fundID?

update [transaction]
set amount = amount - (select (a.amount + sum(b.amount)) amt
                       from [Transaction] a
                            inner join [transaction] b on a.FundID=b.FundID
                                                     and a.TransactionBatchID=b.TransactionBatchID
                            inner join fund c on a.fundid=c.FundID
                       where a.TransactionBatchID=19253 and a.TransactionTypeID=1308 and a.TransactionCategoryID=82
                        and b.TransactionCategoryID=83 and c.PoolID=78
                       group by a.amount, b.fundid
                       having a.amount * (-1) <> sum(b.amount))
where transactionid=(select max(transactionid)
                     from [transaction]
                     where TransactionBatchID=19253
                       and TransactionTypeID=1308
                       and TransactionCategoryID=83
                     group by fundid)

标签: sql-serverdata-bindingbindingsubquery

解决方案


推荐阅读