How to batch update mysql according to respective conditions
代言
代言 2017-06-26 10:49:25
0
1
1021

There are two tables, A is the detailed table
id uid cost

    1. 0

    1. 1

    1. 4

    1. 3

Now we need to group the data with cost greater than 0 in the table according to uid and update it to another table

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

This is the statement taken out. Is there any way to update the query results to another table based on uid in one sentence?

代言
代言

reply all(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)
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template