相当基本;组功能无效。我知道我需要使用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';
答案 0 :(得分:0)
您不能使用聚合函数(如count而不使用group by)并将此值作为结果分配 在这种情况下,您应该使用适当的子选择来获取要在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';