gpt4 book ai didi

mysql - 使用 Join 更新 Coldfusion ORM

转载 作者:行者123 更新时间:2023-11-29 06:15:31 25 4
gpt4 key购买 nike

我正在寻求有关 HQL 语句的帮助,我想在其中使用 JOIN 进行更新。我尝试了以下语句,它在 MySQL-Workbench 中运行良好:

UPDATE table1 t1 
SET t1.status='Running'
JOIN t1.table2 t2
WHERE t1.status='Open' AND t2.destination ='mydestination' "

但它给出了错误:

expecting "set", found 'JOIN' near line 1, column 16

最佳答案

在我看来,因为这是一个批量更新操作,所以您应该对此使用 SQL 而不是 HQL。 ORM 并不是真正为这种类型的更新而设计的。您始终可以运行 SQL 语句,然后在需要时加载对象图(您的 ORM 实体)。

至于 SQL,您需要使用 cfquery(或等效的 cfscript)来运行它,从您的 HQL 示例来看,它看起来像这样作为 SQL(假设您提到的 MySQL 是 MySQL工作台)

<cfquery>
UPDATE table1 t1
INNER JOIN table2 t2 ON t1.col = t2.col
SET status='Running'
WHERE status='Open'
AND t2.destination='mydestination'
</cfquery>

如果你想用 HQL 来做,那么你通常需要使用子查询。像这样:

update table1 t1 
set t1.status = 'Running'
where t1.state = 'Open'
and t1 in (
select t2.table1
from table2 t2
where t2.destination='mydestination'
)

关于mysql - 使用 Join 更新 Coldfusion ORM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36112496/

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