【发布时间】:2016-12-17 17:07:36
【问题描述】:
为某些语料库更新字典中的常用术语计数。无法在单个查询中执行。相反,我将计数数据收集到一个临时表中,然后插入/更新字典。想知道在单个命令中更新 countInCorpus 的正确语法是什么。
当前语法:
INSERT INTO temp_table (name, countInCorpus)
SELECT name,count(*) AS theCount
FROM corpus
GROUP BY name having theCount > 9);
INSERT INTO dict (name, countInCorpus)
SELECT name, countInCorpus
FROM temp_table ON DUPLICATE KEY UPDATE dict.countInCorpus=temp_table.countInCorpus;
一步语法失败(导致“字段列表中的未知列 'theCount'”):
INSERT INTO dict (name, countInCorpus)
SELECT name,count(*) AS theCount
FROM corpus
GROUP BY name having theCount > 9
ON DUPLICATE KEY UPDATE dict.countInCorpus=theCount;
【问题讨论】:
标签: mysql group-by sql-update sql-insert