相当基本;群组功能无效。我知道我需要使用 HAVING 但不知道如何重写它。
update deals d
join deal_products dp on dp.deal_id = d.id
set d.products_count = count(distinct product_id)
where dp.active_flag=1 and dp.enabled_flag=1 and d.status != 'deleted';
最佳答案
您无法使用没有分组依据的聚合函数(例如 count)并将该值指定为结果
在这种情况下,您应该使用适当的子选择来获取要在 d.products_count 处分配的值
update deals d
join deal_products dp on dp.deal_id = d.id
set d.products_count = (select count(distinct product_id)
from your_table where Your_condition)
where dp.active_flag=1 and dp.enabled_flag=1 and d.status != 'deleted';
关于mysql - 这里有一些基本的东西 : Invalid Group function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39775438/