2

我正在尝试使用“ON DUPLICATE KEY UPDATE”语句运行基于 SELECT 的 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

欢迎所有帮助...

4

1 回答 1

3

就在您决定寻求帮助时,您一如既往地想出了解决方案。

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”。

于 2013-12-09T22:39:16.063 回答