选择小于一周的 PostgreSQL 表行



我正在创建一个聊天框,遇到了问题。我只想选择不到一周前插入到表中的行。我将如何在PostgreSQL中做到这一点?我的插入代码在这里:

echo $db->query_one_field("select json_build_object('max',max(chat_id),'chats',array_to_json(array_agg(z))) from (select chat_id, to_char(time,'Day HH24:MI') timee, name, text from chat where chat_id>$1 order by chat_id) z",$_GET['newfrom']);

我已经读过这个: PostgreSQL:选择不到 15 分钟的地方,但我不确定如何将其集成到我的代码中,因为我是 PHP 的新手

只需将此子句添加到查询中即可。

后:

where chat_id>$1

and time > now() - '1 week'::interval

最新更新