gpt4 book ai didi

MySQL key ON DUPLICATE KEY UPDATE 列不明确

转载 作者:行者123 更新时间:2023-11-29 01:17:31 24 4
gpt4 key购买 nike

有如下问题

INSERT INTO statistics_new (SELECT * FROM statistics)
->
-> ON DUPLICATE KEY UPDATE
->
-> end_date = IF(end_date < VALUES(end_date), VALUES(end_date), end_date);
ERROR 1052 (23000): Column 'end_date' in field list is ambiguous

当我尝试按照 http://dev.mysql.com/doc/refman/5.0/en/insert-select.html 中的建议指定列和表别名时我得到了相同的结果。

服务器版本:5.5.24-0ubuntu0.12.04.1 (Ubuntu)

下面的查询运行没有问题:

INSERT INTO statistics_new (SELECT * FROM statistics)
ON DUPLICATE KEY UPDATE
end_date = VALUES(end_date)

最佳答案

SQLFiddle example

基本上我想你想要这个:

INSERT INTO statistics_new (SELECT * FROM statistics)
ON DUPLICATE KEY UPDATE
statistics_new.end_date = if(statistics_new.end_date < statistics.end_date,
statistics.end_date, statistics_new.end_date);

关于MySQL key ON DUPLICATE KEY UPDATE 列不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13267152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com