SQL语句怎么累加

zglikai 2003-07-21 06:15:45
month earning add_up
第1月 100元 100元
第2月 200元 300元
第3月 300元 900元


我想通过SQL语句使 ,第2月的add_up等于第1月的earning(100元)
加上第2月earning(200元)
第3月的add_up等于第1月的earning(100元)
加上第2月earning(200元)
加上第3月earning(300元)
...全文
147 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
zglikai 2003-07-22
  • 打赏
  • 举报
回复
可以用一个select语句吗?
longji 2003-07-22
  • 打赏
  • 举报
回复
update tablename set add_up=(select sum(earning) from tablename where month<=a.month) from tablename as a
pengdali 2003-07-22
  • 打赏
  • 举报
回复
或:
update 表 set add_up=(select sum(earning) from 表 tem where tem.month<=表.month)
pengdali 2003-07-22
  • 打赏
  • 举报
回复
declare @a int
set @a=0
update 表 set @a=@a+earning,add_up=@a
jiutiao 2003-07-22
  • 打赏
  • 举报
回复
update table set add_up=(select sum(earning) from table where month<=month)
txlicenhe 2003-07-22
  • 打赏
  • 举报
回复
update 表 set add_up=(select sum(earning) from 表 tem where tem.month<=表.month)

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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