gpt4 book ai didi

mysql - 如何检查两个MySQL表中两个时间之间的差异?

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

所以我有两个表:

ic:

id | created
---|--------------------
1 | 2016-03-31 16:20:03
2 | 2016-03-31 16:25:18
3 | 2016-03-31 16:28:09

状态:

id | ic_id | timestamp
---|--------------------
1 | 1 | 2016-03-31 16:20:03
2 | 5 | 2016-03-31 16:25:18
3 | 5 | 2016-03-31 16:28:09

我现在想要找到 status 中第一个相应记录的 ic.createdstatus.timestamp 之间的平均差异 table 。我从这个开始:

SELECT status.`timestamp` - informed_consent.created as difference
FROM status
WHERE status.`timestamp` > '2017-06-19'
AND status.ic_id IN (
SELECT informed_consent.id
FROM informed_consent
WHERE informed_consent.id = status.ic_id;
);

但我立即在 mysql 语法中发现错误。我想我也可以使用左连接,但我有点迷失在这里。

有人能帮我找到正确的方向吗?

最佳答案

我认为您可以使用inner join而不是子查询,因为informed_consent.created不存在于外部sql中,它存在于子查询

SELECT status.`timestamp`,status.`timestamp` - informed_consent.created as difference
FROM status
JOIN informed_consent ON informed_consent.id = status.ic_id
WHERE status.`timestamp` > '2017-06-19'

关于mysql - 如何检查两个MySQL表中两个时间之间的差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50927636/

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