From: AnthonyV <avequeau@gmail.com>
To: pgsql-sql@postgresql.org
Subject: SQL Subqueries on each result row
Date: Wed, 23 Sep 2009 02:43:37 -0700 (PDT)
Message-ID: <b4fa00ca-986f-4a57-8690-e7d234ba6ebd@o21g2000vbl.googlegroups.com> (raw)
Hello,
I have a table like :
date | value
-------------------------------
2009-09-19 | 1
2009-09-20 | 2
2009-09-21 | 6
2009-09-22 | 9
2009-09-23 | 1
I'd like a request which gives me the sum of each last n days.
For example, if I want the sum of each 3 days, I want this result:
date | sum_value
-------------------------------
2009-09-19 | 1 (sum from 2009-09-17 to 2009-09-19)
2009-09-20 | 3 (sum from 2009-09-18 to 2009-09-20)
2009-09-21 | 9 (sum from 2009-09-19 to 2009-09-21)
2009-09-22 | 17 (sum from 2009-09-20 to 2009-09-22)
2009-09-23 | 16 (sum from 2009-09-21 to 2009-09-23)
I try to make a subquery which is apply on each row of a query, but it
does work.
Has anybody an idea?
Thanks in advance!
Anthony
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: avequeau@gmail.com
Subject: Re: SQL Subqueries on each result row
In-Reply-To: <b4fa00ca-986f-4a57-8690-e7d234ba6ebd@o21g2000vbl.googlegroups.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox