gpt4 book ai didi

php - PostgreSQL 获取过去 12 小时内的项目

转载 作者:可可西里 更新时间:2023-10-31 22:08:46 25 4
gpt4 key购买 nike

我有以下查询来在 PHP 文件中获取我想要的内容,除了 WHERE 部分之外,它完成了它的工作。我需要获取过去 12 小时内具有 date_time1 列的项目。

SELECT p.*, t.* 
FROM posts AS p
LEFT JOIN posted_tweets AS t
ON p.a_id = t.p_id
WHERE p.date_time1 >= now() AND t.date_time =
(
SELECT MAX(date_time)
FROM posted_tweets AS t2
WHERE t2.p_id = t.p_id
)
OR t.date_time IS NULL

我究竟应该如何编辑 p.date_time1 >= now() 部分才能达到我的目标?谢谢。

最佳答案

以下应限制为过去 12 小时内发生的所有时间:

w.date_time1 >= (NOW() - INTERVAL '12 hours' )

检查 here有关在 Postgresql 中处理日期时间的良好讨论以及示例。

关于php - PostgreSQL 获取过去 12 小时内的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32323426/

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