今天遇到這個Error 滿神奇的,只有出現在部份的 MySQL server 上。我的 SQL:
update TABLE_A as c inner join (select count(*) as MY_COUNT, l1.device_id from TABLE_B as l1 where l1.log_datetime >=DATE(now()) AND l1.source=3) as l2 set c.MY_COUNT = l2.MY_COUNT where c.createdTime>=DATE(now()) AND c.enroll_id=l2.device_id;
為什麼會用到這一組 SQL , 參考這一篇:
MySQL – Update values based on subquery
https://stackoverflow.max-everyday.com/2017/10/mysql-update-values-based-on-subquery/
解法,把需要 display 的欄位,多增加到 order by 裡,即可解決。