达到总和后停止SQL选择
我的数据库是IBM i的DB2。
我有只读访问权限,因此我的查询必须仅使用基本的SQL选择命令。
=============================================== ============
目标:
我想选择表中的每个记录,直到金额列的总和超过预定限制为止。
示例:
我想匹配表下的每个项目,直到“价格”列中的匹配值和$ 9.00。
所需的结果:
这可能吗?
My database is Db2 for IBM i.
I have read-only access, so my query must use only basic SQL select commands.
==============================================================
Goal:
I want to select every record in the table until the sum of the amount column exceeds the predetermined limit.
Example:
I want to match every item down the table until the sum of matched values in the "price" column >= $9.00.
The desired result:
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
sum
分析函数来计算运行总计的总价格,然后按其值过滤:db<> fiddle
You may use
sum
analytic function to calculate running total of price and then filter by its value:db<>fiddle here