PostgreSQL:SELECT WHERE不到15分钟

时间:2014-04-13 14:41:46

标签: sql postgresql select timestamp

从下面的events表中,如何选择不到15分钟前创建的events

CREATE TABLE events (
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
);

2 个答案:

答案 0 :(得分:56)

SELECT created_at FROM events WHERE created_at > NOW() - INTERVAL '15 minutes';

答案 1 :(得分:9)

SELECT * FROM events WHERE age(now(), created_at) < '15 minutes';