原文地址 http://stackoverflow.com/questions/3022405/mysql-update-query-with-left-join-and-group-by
UPDATE Table AS t LEFT JOIN ( SELECT Index1, Index2, COUNT(EventType) AS NumEvents FROM MEvents WHERE EventType = ‘A‘ OR EventType = ‘B‘ GROUP BY Index1, Index2 ) AS m ON m.Index1 = t.Index1 AND m.Index2 = t.Index2 SET t.SpecialEventCount = m.NumEvents WHERE t.SpecialEventCount IS NULL
时间: 2024-11-03 21:00:28