gpt4 book ai didi

sql - Postgresql 在 UPDATE 请求中添加 WHERE 子句

转载 作者:行者123 更新时间:2023-11-29 14:38:12 24 4
gpt4 key购买 nike

我打算写一个 SQL 请求 UPDATE,我想验证 table2.fld5 是否已经包含 'Hello' 为了不写几次,但没有找到实现此验证的方法。

请求是:

UPDATE table2
SET fld5 = concat(fld5, 'Hello')
WHERE NOT EXISTS (SELECT *
FROM table1
WHERE table1.fld1 = table2.fld1 AND
table1.fld2 = table2.fld2 AND
table1.fld3 = table2.fld3
)
AND table2.fld4 > (NOW() - INTERVAL '79 MINUTE');

最佳答案

也许您的日期检查需要在现有子查询之外:

UPDATE table2 SET fld5 = concat(fld5, 'Hello') 
WHERE fld5 NOT LIKE '%Hello%' AND table2.fld4 > (NOW() - INTERVAL '79 MINUTE'
AND NOT EXISTS (SELECT * FROM table1 WHERE table1.fld1 = table2.fld1 AND table1.fld2 = table2.fld2 AND table1.fld3 = table2.fld3))

;

关于sql - Postgresql 在 UPDATE 请求中添加 WHERE 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41038919/

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