I am in contact with a business that updates 39718 pieces of data every 15s, and each piece of data comes from many different tables. Then I use business code to do it, and the execution time is more than half an hour, which is far beyond 15s. So use sql batch update to deal with the business. sql only took 0.516s.
First prepare two sheets A and B. as follows:
A:
B:
According to the t_name field of table A, associate table B to query the number of t_names.
SELECT a1.t_name, COUNT(a1.id) AS number FROM a AS a1 LEFT JOIN b ON a1.t_name = b.t_name GROUP BY a1.t_name
The result is as follows:
Then batch update is performed based on the same field t_name as the associated field, as follows:
UPDATE a SET a.t_value = ( SELECT t.number FROM ( SELECT a1.t_name, COUNT(a1.id) AS number FROM a AS a1 LEFT JOIN b ON a1.t_name = b.t_name GROUP BY a1.t_name ) t WHERE t.t_name = a.t_name )
Results of the: