[MySQL] Error Code: 1140. In aggregated query without GROUP BY, expression #2 of SELECT list contains nonaggregated column; this is incompatible with sql_mode=only_full_group_by

今天遇到這個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
http://stackoverflow.max-everyday.com/2017/10/mysql-update-values-based-on-subquery/

 

解法,把需要 display 的欄位,多增加到 order by 裡,即可解決。

相關文章

寫留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *