0

我对 MySQL 更新语句有疑问。我在表中有超过 100.000 个条目。所以我的方法没有成功。(见下文)

首先,我想计算值的数量(这很容易):

SELECT values1 ,count(values1) FROM table
GROUP BY value1
HAVING COUNT(value1) <= 1000;

其次,我想替换仅出现 <= 1000 次的列 values1 的一些值。

所以我尝试了这些说法:

Update table as t
SET t.value1 = "limitAmount" 
WHERE EXISTS (select value1 from 
(select * from table) as f Group by f.value1
Having count(f.value1) <= 1000);

当我尝试这条 SQL 语句时,我收到:

错误代码 1205。超过锁定等待超时。尝试重新启动事务。

4

2 回答 2

1

尝试这个

Update 
  table as t 
SET 
  t.value1 = "limitAmount" 
WHERE 
  EXISTS (select value1 from (select * from table) as f where f.value1 = t.value1 Group by f.value1 Having count(f.value1) <= 1000);

通知where f.value1 = t.value1中的条件subquery

于 2013-05-04T19:27:31.157 回答
0

该声明有效:

UPDATE test SET val="BLUB" WHERE val IN (SELECT val FROM (SELECT val FROM test GROUP BY val HAVING COUNT(val) <2000) war);

选择:

  1. 将值添加到单独的表 INSERT INTO helpTable (Value1) (select val FROM test Group by val 有 count(val) <= 2000);

  2. 选择 Update test as t SET t.val = "BLUB" WHERE NOT EXISTS (Select Value1 from helpTable as h WHERE t.val = h.Value1);

于 2013-05-05T13:02:16.627 回答