mysql如何根据各自条件批量更新

现有两张表,A是明细表

id      uid       cost
1.       233.      0
2.        244.     1
3.       133.      4
4.        133.      3

现在要把把该表中cost大于0的数据,根据uid分组然后更新到另一个表上

select uid,count(cost) as count from A where cost > 0 group by uid 

这是取出的语句,有没办法一句话把这个查询结果根据uid更新到另一张表上?

阅读 6.1k
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)
推荐问题
宣传栏