gpt4 book ai didi

MySql 使用嵌套选择插入动态查询

转载 作者:行者123 更新时间:2023-11-29 22:14:35 25 4
gpt4 key购买 nike

我正在尝试混合静态和动态值的 MySQL 插入查询。 INSERT 命令是。

    INSERT INTO ebdb.requestaction(RequestID,
ActionID,
TransactionID,
IsActive,
IsComplete)
VALUES (
1,
**Dynamic Value from Below Query,
Dynamic Value from Below Query,**
1,
0);

获取字段 2 和 3 的查询来自以下查询。

    SELECT transitionaction.TransitionID, transitionaction.ActionID
FROM transitionaction
INNER JOIN transition
ON transitionaction.TransitionID = transition.TransitionID
WHERE transition.TenantID = 1
AND transition.ProcessID = 1
AND transition.CurrentStateID = 1
ORDER BY transitionaction.TransitionID;

我在这里做错了什么。请指导我如何以最优化的方式实现这一目标。

最佳答案

您可以选择静态值作为查询的一部分,例如:

INSERT INTO ebdb.requestaction(RequestID, ActionID, TransactionID, IsActive, IsComplete)
SELECT 1, transitionaction.ActionID, transitionaction.TransitionID, 1, 0
FROM transitionaction
INNER JOIN transition
ON transitionaction.TransitionID = transition.TransitionID
WHERE transition.TenantID = 1
AND transition.ProcessID = 1
AND transition.CurrentStateID = 1
ORDER BY transitionaction.TransitionID;

更多信息,请参阅MySQL's Insert...Select Syntax

关于MySql 使用嵌套选择插入动态查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31315198/

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