【发布时间】:2017-03-24 21:06:00
【问题描述】:
我正在创建一个聊天框,但遇到了问题。我只想选择不到一周前插入到表中的行。我将如何在 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: SELECT WHERE less than 15 minutes old 但我不确定如何将它集成到我的代码中,因为我是 PHP 新手
【问题讨论】:
-
在
where chat_id>$1之后添加`和时间> now() - '1 week'::interval` -
谢谢,一周后我可以告诉你它是否有效!
-
出于兴趣,你为什么不回答这个问题?
-
抱歉 - 我不确定我是否理解正确。所以首先检查,如果它是你想要的,我会回答确认
-
这就是我想要的,抱歉我不清楚。
标签: php sql postgresql