gpt4 book ai didi

mysql - 如何将两个查询合并为一行查询

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

我想使用第一个查询结果应用于第二个查询。然后我遇到了一些问题。

(我的环境是Node.js,但不会造成这个问题的影响。)

<小时/>

第一个查询

SELECT (TO_SECONDS('2015-02-10 23:00:00') - TO_SECONDS(NOW())) AS remainSeconds

然后我将得到数字结果“remainSeconds”,如“-1957”。

如果 'remainSeconds' > 0 将运行第二个查询。

第二个查询

// '...' is not important, so I skip them.

INSERT INTO tableA(...) SELECT ... FROM tableB
<小时/>

我的问题摘要:

We know there is some delay between the two queries running. And this delay time will cause some critical problems in some cases.

How to combine above two queries in to the one line query.

最佳答案

只需在 SELECT 的位置添加 (TO_SECONDS('2015-02-10 23:00:00') - TO_SECONDS(NOW()))

例如

插入表A(...)
选择 ...
来自表B
WHERE (TO_SECONDS('2015-02-10 23:00:00') - TO_SECONDS(NOW())) > 0

关于mysql - 如何将两个查询合并为一行查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28435820/

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