• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

问下这个SQL的写法

php 搞代码 3年前 (2022-01-23) 10次浏览 已收录 0个评论
文章目录[隐藏]

本帖最后由 u011669689 于 2013-09-25 18:25:00 编辑

sql select update

基础条件:
user表 userid ,username
user_money 表 u_id,user_money
user_money_exchange 表:money ,username,ordertag =1或2

现在想执行:

update user_money set user_money = (user_money_exchange 当ordertag =1的 sum(money) + 当ordertag =2的 sum(money)) where user_money.u_id = user.userid

update user_money set user_money.money = (select sum(ume.money) as m , u.userid from user_money_exchange ume  left join user u on ume.username = u.username where ume.ordertag = 1 group by ume.username + select sum(ume.money) as m , u.userid from user_money_exchange ume  left join user u on ume.username = u.username where ume.ordertag = 2 group by ume.username) where user_money.u_id = u.userid

这个是错的,想知道对的是?谢谢各位了

回复讨论(解决方案)

先获取相关的数据出来,之后在执行update。印象中不能这么写

试试

update user_money um left join user u on um.u_id=u.useridleft join  (select usern<div style="color:transparent">本文来源gaodai.ma#com搞##代!^码@网*</div><pre>搞gaodaima代码

ame,sum(money) as moneys from user_money_exchange group by username) umeon ume.username=u.usernameset um.money = ume.moneys

谢谢,可行,非常感谢


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:问下这个SQL的写法

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址