同时在mysql中更新相同的表跳过某一行

时间:2013-09-09 14:11:02

标签: mysql sql

我试图通过连接相同的表来更新相同的表,重复行跳过。我想在number_of_duplicates字段中存储重复值的计数。

UPDATE 4_crem_three_entries a,(
    SELECT count(*) c,cream_id FROM 4_crem_three_entries 
    GROUP BY `c_phone` HAVING count( * ) >1
   ) b
SET number_of_duplicates=b.c 
WHERE a.cream_id=b.cream_id

1 个答案:

答案 0 :(得分:0)

试试这个

UPDATE 4_crem_three_entries 
SET number_of_duplicates=(SELECT count( * ) FROM 4_crem_three_entries c where c.cream_id=4_crem_three_entries.cream_id GROUP BY c.c_phone HAVING count( * ) >1)