我正在从 tableONE 查询并尝试将结果集插入到 tableTWO 中。这有时会导致 tableTWO 中出现重复键错误。所以我想ON DUPLICATE KEY UPDATE
从 tableONE 结果集中使用新确定的值,而不是用ON DUPLICATE KEY UPDATE columnA = columnA
.
INSERT INTO `simple_crimecount` (`date` , `city` , `crimecount`)(
SELECT
`date`,
`city`,
count(`crime_id`) AS `determined_crimecount`
FROM `big_log_of_crimes`
GROUP BY `date`, `city`
) ON DUPLICATE KEY UPDATE `crimecount` = `determined_crimecount`;
# instead of [ON DUPLICATE KEY UPDATE `crimecount` = `crimecount`];
它返回一个错误,说明以下内容
Unknown column 'determined_crimecount' in 'field list'