INSERT ...使用WHERE在重复密钥更新上?

编程入门 行业动态 更新时间:2024-10-27 20:26:38
本文介绍了INSERT ...使用WHERE在重复密钥更新上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在执行INSERT ... ON DUPLICATE KEY UPDATE,但是我需要更新部分是有条件的,只有在某些额外条件发生变化时才进行更新.

I'm doing a INSERT ... ON DUPLICATE KEY UPDATE but I need the update part to be conditional, only doing the update if some extra condition has changed.

但是,此UPDATE上不允许使用WHERE.有什么解决方法吗?

However, WHERE is not allowed on this UPDATE. Is there any workaround for this?

我无法进行INSERT/UPDATE/SELECT的组合,因为这需要对复制进行工作.

I can't do combinations of INSERT/UPDATE/SELECT since this needs to work over a replication.

推荐答案

我建议您使用IF()来做到这一点.

I suggest you to use IF() to do that.

引用: conditional-duplicate-key-updates-with-mysql

INSERT INTO daily_events (created_on, last_event_id, last_event_created_at) VALUES ('2010-01-19', 23, '2010-01-19 10:23:11') ON DUPLICATE KEY UPDATE last_event_id = IF(last_event_created_at < VALUES(last_event_created_at), VALUES(last_event_id), last_event_id);

更多推荐

INSERT ...使用WHERE在重复密钥更新上?

本文发布于:2023-10-23 03:33:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519631.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:密钥   新上   INSERT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!