pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Broersma <richard.broersma@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: graphing time series data
Date: Wed, 14 Apr 2010 08:46:13 -0700
Message-ID: <r2k396486431004140846y4579154erc604d6286ac2cb89@mail.gmail.com> (raw)
In-Reply-To: <20100414145434.GA13682@apartia.fr>
References: <20100414145434.GA13682@apartia.fr>

On Wed, Apr 14, 2010 at 7:54 AM, Louis-David Mitterrand
<vindex+lists-pgsql-sql@apartia.org> wrote:

> Now, I'd like to make a graph of average prices per week, per
> id_product. As some prices don't vary much, distribution would not be
> ideal if I simply 'group by extract(week from p.modified)'.

I created a view for a similar problem that I had.  Only I was
calculating the counts per day.  this query could be crafted to work
for you.

CREATE OR REPLACE VIEW opendiscrepencydailycounts AS
 WITH opendays(day) AS (
         SELECT gs.day::date AS day
           FROM generate_series((( SELECT
min(discrepencylist.discstartdt) AS min
                   FROM discrepencylist))::timestamp without time
zone, 'now'::text::date::timestamp without time zone, '1
day'::interval) gs(day)
        )
 SELECT opendays.day, ds.resolvingparty, count(opendays.day) AS
opendiscrepancies
   FROM discrepencylist ds, opendays
  WHERE opendays.day >= ds.discstartdt AND opendays.day <=
LEAST('now'::text::date, ds.resolutiondate)
  GROUP BY opendays.day, ds.resolvingparty
  ORDER BY opendays.day, ds.resolvingparty;


-- 
Regards,
Richard Broersma Jr.

Visit the Los Angeles PostgreSQL Users Group (LAPUG)
http://pugs.postgresql.org/lapug



view thread (6+ messages)  latest in thread

Message-ID: <r2k396486431004140846y4579154erc604d6286ac2cb89@mail.gmail.com>
Permalink:  ../r2k396486431004140846y4579154erc604d6286ac2cb89@mail.gmail.com/
Also on:    postgresql.org/message-id/r2k396486431004140846y4579154erc604d6286ac2cb89@mail.gmail.com

 · 

reply

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: richard.broersma@gmail.com
  Subject: Re: graphing time series data
  In-Reply-To: <r2k396486431004140846y4579154erc604d6286ac2cb89@mail.gmail.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