gpt4 book ai didi

mysql - 如果mysql中的数据发生更改,如何删除旧条目同时插入新条目

转载 作者:行者123 更新时间:2023-11-29 17:30:14 27 4
gpt4 key购买 nike

如果数据重复,如何在插入新条目时删除旧条目。就我而言,每天晚上都会运行一个作业来插入新记录,但是当记录有任何更改时,它会插入新记录而不是删除旧记录。

SELECT
op.order_product_id,
op.order_id,
o.date_added as booking_date,
o.date_modified,
o.order_status_id as order_status,

REVERSE(SUBSTRING_INDEX(REVERSE(op.resource), '/' , 1)) as entity_id,
op.name as stay_name,
CASE WHEN op.legacy_product_id IS NULL THEN op.product_id ELSE op.legacy_product_id END as legacy_product_id,
op.total as stay_amount

FROM opencart.order_product op
LEFT JOIN opencart.order o ON o.order_id = op.order_id
LEFT JOIN opencart.order_option ot ON ot.order_id = op.order_id AND ot.name = 'Anzahl der Personen'

where op.product_id NOT IN (2,3,5)
AND o.order_status_id IN (5,7)

AND DATE(o.date_modified) >= current_date() - INTERVAL 3 DAY
AND DATE(o.date_modified) < current_date()

GROUP BY 1

最佳答案

自从您显示 SELECT 请求并谈论更新数据以来,我不太确定我是否理解您的观点。我的猜测是,在此选择之后,您只需使用 INSERT 而不是 UPDATE。您应该快速浏览一下此链接 https://www.w3schools.com/sql/sql_update.asp你应该能够做你想做的事情

关于mysql - 如果mysql中的数据发生更改,如何删除旧条目同时插入新条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50722049/

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