update语句能和insert一样有嵌套么?这个应该怎么写?

sperfect 2003-12-08 07:47:47
就如:
insert into total (uid,getflow,sendflow)
select uid,sum(getflow),sum(sendflow) from wlog
group by uid;
把wlog中的getflow和sendflow按照uid分别求和,然后把结果插到total中。
现在想再做一个这样的操作:
insert into total (uid,outflow)
select uid,sum(getflow) from wlog
where isout='y'
group by uid;
就是在把getflow按照isout的属性做个求和,把结果还是插在total中,只是不能再用insert了,要用update,因为同一个uid只能有一条记录,应该怎么做?
谢谢!
...全文
126 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sperfect 2003-12-09
  • 打赏
  • 举报
回复
update中不能使用from子句的。
伍子V5 2003-12-09
  • 打赏
  • 举报
回复
try:
update total set outflow=b.getflow from total a,(select uid,sum(getflow) getflow from wlog where isout='y' group by uid) b where a.uid=b.uid

56,677

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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