现在有两张表t_user1,t_user2,这两张表有1个相同名称的列id,其中id为主键,另外t_user1有列total_amount,t_user2有列amount。我现在想把t_user2的amount列的数据
进行汇总并且将结果更新到t_user1中,请问对应的sql该怎么写,可以用存储过程,谢谢了
进行汇总并且将结果更新到t_user1中,请问对应的sql该怎么写,可以用存储过程,谢谢了
调试欢乐多
update t1 a inner join
(select id,sum(amount) as sa from t2 group by id) b
on a.id=b.id
set a.amount=b.sa
create table tem1
select id,sum(amount) as all from t_user2
group by idupdate t_user1 A,tem1 B
set A.total_amount=B.all
wher A.id=B.id
命题: 每日 02:00 am 定时删除 表 t (id int primary key,ptime TIMESTAMP DEFAULT CURRENT_TIMESTAMP) 中三天以前的记录。 ======================================= 方法一:操作系统 ======================================= (...
set A.total_amount=B.amount
where A.id=B.id ;