簡體   English   中英

選擇少於一周的PostgreSQL表行

[英]Select PostgreSQL table rows younger than a week

我正在創建一個聊天框,並且遇到了問題。 我只想選擇不到一周前插入表中的行。 我將如何在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不到15分鍾,但是我不確定如何將其集成到我的代碼中,因為我是PHP新手。

只需將此子句添加到查詢中即可。

后:

where chat_id>$1

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM