How to list records with date from the last 10 days?

前端 未结 6 449
Happy的楠姐
Happy的楠姐 2020-12-13 01:36
SELECT Table.date FROM Table WHERE date > current_date - 10;

Does this work on PostgreSQL?

6条回答
  •  一生所求
    2020-12-13 02:35

    My understanding from my testing (and the PostgreSQL dox) is that the quotes need to be done differently from the other answers, and should also include "day" like this:

    SELECT Table.date
      FROM Table 
      WHERE date > current_date - interval '10 day';
    

    Demonstrated here (you should be able to run this on any Postgres db):

    SELECT DISTINCT current_date, 
                    current_date - interval '10' day, 
                    current_date - interval '10 days' 
      FROM pg_language;
    

    Result:

    2013-03-01  2013-03-01 00:00:00 2013-02-19 00:00:00
    

提交回复
热议问题