2016-09-29 40 views
0

相當基本;組函數無效。我知道我需要使用HAVING,但不知道如何重寫它。這裏基本的東西:無效的組功能

+0

可能重複的[是否有任何\ _VALUE能力的MySQL 5.6?](http://stackoverflow.com/questions/37089347/is-there-any-value-capability-for-mysql-5-6 ) – e4c5

回答

0

您無法通過使用像計數聚合函數沒有一個組,然後分配到該值,結果
在這種情況下,你應該使用合適的子查詢爲獲得價值在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';