Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 03624633F46 for ; Wed, 23 Sep 2009 07:03:33 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 93534-07 for ; Wed, 23 Sep 2009 10:03:25 +0000 (UTC) Received: from news.hub.org (news.hub.org [200.46.204.72]) by mail.postgresql.org (Postfix) with ESMTP id 95217632F8C for ; Wed, 23 Sep 2009 07:03:25 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.14.3/8.14.3) with ESMTP id n8NA3L6A029565 for ; Wed, 23 Sep 2009 07:03:21 -0300 (ADT) (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.14.3/8.14.3/Submit) id n8N9hYt4019113 for pgsql-sql@postgresql.org; Wed, 23 Sep 2009 06:43:34 -0300 (ADT) (envelope-from news) From: AnthonyV X-Newsgroups: pgsql.sql Subject: SQL Subqueries on each result row Date: Wed, 23 Sep 2009 02:43:37 -0700 (PDT) Organization: http://groups.google.com Lines: 31 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Complaints-To: groups-abuse@google.com Complaints-To: groups-abuse@google.com Injection-Info: o21g2000vbl.googlegroups.com; posting-host=86.64.141.252; posting-account=48sjYAoAAABYBLY_M661dLOOE79gHleb User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 GTB5 (.NET CLR 3.5.30729), gzip(gfe), gzip(gfe) To: pgsql-sql@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 200909/112 X-Sequence-Number: 33177 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