hot*_*oup 0 sql postgresql timestamp
Postgres在这里;我有一个Users包含以下字段的表:
create table Users (
id bigserial primary key,
isAdmin boolean not null default false,
beginDate timestamp with time zone not null,
updated timestamp with time zone
);
Run Code Online (Sandbox Code Playgroud)
我想写一个查询来获取所有Users记录:
beginDate过去24小时(包括性)内的值; 和updated是值较旧的(唯一的)超过24小时到目前为止,我最好的尝试是:
select *
from
Users
where
beginDate >= NOW() - INTERVAL 1 DAY and
updated < NOW() - INTERVAL 1 DAY
Run Code Online (Sandbox Code Playgroud)
但这给了em以下错误:
ERROR: syntax error at or near "1"
Position: 59
beginDate >= NOW() - INTERVAL 1 DAY and
^
1 statement failed.
Execution time: 0.03s
Run Code Online (Sandbox Code Playgroud)
有什么解决办法的想法吗?
小智 5
正确的语法是这样的:
beginDate >= NOW() - INTERVAL '1 DAY' and
updated < NOW() - INTERVAL '1 DAY'
Run Code Online (Sandbox Code Playgroud)
您可以在这里找到更多信息:https : //www.postgresql.org/docs/current/functions-datetime.html