作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试基于 SELECT 和“ON DUPLICATE KEY UPDATE”语句运行 INSERT 查询。 SELECT 查询有效,如果我“手动”输入结果数据,将导致重复键问题。到目前为止,一切都很好。但是,下面的查询似乎没有像我预期的那样更新“et_report_ymd.quotes”中的值。
INSERT IGNORE INTO et_report_ymd
SELECT
NULL,
t.year AS year,
t.month AS month,
t.day AS day,
SUM(t.quotes) AS quotes
FROM source_table AS t
GROUP BY t.year, t.month, t.day
ON DUPLICATE KEY UPDATE
et_report_ymd.quotes = quotes
欢迎所有帮助...
最佳答案
就在您决定寻求帮助时,您一如既往地想出了解决方案。
INSERT IGNORE INTO et_report_ymd
SELECT
NULL,
t.year AS year,
t.month AS month,
t.day AS day,
SUM(t.quotes) AS quotes
FROM source_table AS t
GROUP BY t.year, t.month, t.day
ON DUPLICATE KEY UPDATE
et_report_ymd.quotes = VALUES(quotes)
请注意查询末尾的“VALUES(quotes)”部分,而不仅仅是“quotes”。
关于mysql - 使用 ON DUPLICATE KEY UPDATE 从 SELECT 插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20482217/
我是一名优秀的程序员,十分优秀!