数据累加到10000时退出

qunw 2004-06-24 07:13:22
表结构
table1
id varchar
price int
----------------------------
id price
a01 65
a02 98
a03 98
b01 54
能否通过SQL语句实现price累计相加,当加到10000时所在行的具体信息,不再执行!
...全文
95 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
cloudchen 2004-06-25
  • 打赏
  • 举报
回复
select *,t=(select sum(price) from 表 where id <= a.id) from 表 a
where (select sum(price) from 表 where id <= a.id) <= 1000
sensorcsdn 2004-06-25
  • 打赏
  • 举报
回复
select a.*, total=(select sum(price) from table1 where id<=a.id) from table1 a
qunw 2004-06-25
  • 打赏
  • 举报
回复
结帐!对了!我的数据的问题
qunw 2004-06-25
  • 打赏
  • 举报
回复
都不对呀!
sunrisehy2003 2004-06-24
  • 打赏
  • 举报
回复
price long

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧