A query for date within a year

Posted by Fabiano PS on Stack Overflow See other posts from Stack Overflow or by Fabiano PS
Published on 2010-03-22T20:27:31Z Indexed on 2010/03/22 20:31 UTC
Read the original article Hit count: 817

Filed under:
|
|

My table is like this on Postgres, note that all days start by 01, there is only 1 entry a month+year

SELECT * FROM "fis_historico_receita" 
+----+------------+---------------+
| id | data       | receita_bruta |
+----+------------+---------------+
| 1  | 2010-02-01 | 100000.0      |
| 2  | 2010-01-01 | 100000.0      |
| 3  | 2009-12-01 | 100000.0      |
| 4  | 2009-11-01 | 100000.0      |
| 5  | 2009-10-01 | 100000.0      |
| 6  | 2009-09-01 | 100000.0      |
| 7  | 2009-08-01 | 100000.0      |
| 8  | 2009-07-01 | 100000.0      |
| 9  | 2009-06-01 | 100000.0      |
| 10 | 2009-05-01 | 100000.0      |
| 11 | 2009-04-01 | 100000.0      |
| 12 | 2009-03-01 | 100000.0      |
| 13 | 2009-02-01 | 100000.0      |
| 14 | 2009-01-01 | 100000.0      |
| 15 | 2008-12-01 | 100000.0      |
+----+------------+---------------+

What I want is to find 12 months starting right from before the current.

I tried this:

select *
from fis_historico_receita
where data in interval '1 year'

I really would like an answer using Interval, +1 goes for everyone that runs on Postgres

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql