文章详情页
mysql如何根据各自条件批量更新
问题描述
现有两张表,A是明细表id uid cost
0
1
4
3
现在要把把该表中cost大于0的数据,根据uid分组然后更新到另一个表上
select uid,count(cost) as count from A group by uid where cost > 0
这是取出的语句,有没办法一句话把这个查询结果根据uid更新到另一张表上?
问题解答
回答1:update B b set b.col=(select count(a.cost) as count from A a where cost > 0 and a.uid=b.uid group by uid)
相关文章:
排行榜