sql-server - 将我获得金额的子查询绑定到我的主查询
问题描述
我需要帮助将我的子查询绑定到我的主查询中。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)
解决方案
推荐阅读
- yaml - CloudFormation yaml - 如何强制数字类型?
- python - python:运行需要较长时间的脚本时,子进程不返回任何内容
- sql - 窗口函数中按日期范围划分
- reactjs - 如何渲染仅在 SPA 中显示特定组件的新路由?
- javascript - 如何使用javascript对动态表执行计算
- javascript - 通过DOM选择器识别对象时如何访问JS类方法
- c++ - 访问结构的字符串数组时出现分段错误
- javascript - 我可以做些什么来隐藏而不是删除我在网站上的图像?
- sql-server - 如何通过不同的默认值使用 Row Num 分区
- angularjs - 带有 Bootstrap 4 的 AngularJS 数据表 - 格式问题