mysql如何实现先查询后更新的sql语句
答案:2 悬赏:0 手机版
解决时间 2021-11-24 16:42
- 提问者网友:藍了天白赴美
- 2021-11-24 09:31
mysql如何实现先查询后更新的sql语句
最佳答案
- 五星知识达人网友:山有枢
- 2021-11-24 10:46
UPDATe men_info as a INNER JOIN (select men_id,sum(amount) as amount from men_recharge_info where busin_type =1 and is_refund=0 and recharge_state=3 group by men_id) as b ON a.id=b.men_id SET a.total_recharge = b.amount;
全部回答
- 1楼网友:酒醒三更
- 2021-11-24 10:55
使用update进行更新追问UPDATE men_id t
INNER JOIN (SELECT men_id,SUM(amount) AS temp FROM men_recharge_info GROUP BY men_id) as m ON m.men_id = t.men_id
SET t.total_recharge = m.temp
这条语句行不行?追答应该是可以的,你也可以试试下面的语句,因为没有你那边的表结构,我写的可能会有点问题需要调整
update men_id t set t.SET t.total_recharge = n.temp
where t.men_id in
(SELECT
m.men_id,
SUM(m.amount) AS temp
FROM men_recharge_info m
GROUP BY men_id) n
INNER JOIN (SELECT men_id,SUM(amount) AS temp FROM men_recharge_info GROUP BY men_id) as m ON m.men_id = t.men_id
SET t.total_recharge = m.temp
这条语句行不行?追答应该是可以的,你也可以试试下面的语句,因为没有你那边的表结构,我写的可能会有点问题需要调整
update men_id t set t.SET t.total_recharge = n.temp
where t.men_id in
(SELECT
m.men_id,
SUM(m.amount) AS temp
FROM men_recharge_info m
GROUP BY men_id) n
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯