Re: Average New Users Per DOW

From: Paul Jungwirth <pj(at)illuminatedcomputing(dot)com>
To: Robert DiFalco <robert(dot)difalco(at)gmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Average New Users Per DOW
Date: 2015-07-06 18:30:32
Message-ID: 559AC948.2010309@illuminatedcomputing.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Thanks Paul, I guess I'm not sure how a generate_series between 0 to 6
> would solve this problem. Wouldn't I have to generate a series based on
> the date range (by day) and then group by DOW _after_ that? Can you give
> me an example of how I'd do it with a series based on 0 to 6?

Looks like David Johnston beat me to it! :-) But this is what I had in mind:

SELECT s.d AS dow,
COUNT(u.id) c
FROM generate_series(0, 6) s(d)
LEFT OUTER JOIN users u
ON EXTRACT(dow FROM created) = s.d
GROUP BY dow
ORDER BY dow
;

You can also get human-readable DOW names by creating a 7-row CTE table
and joining to it based on the numeric dow.

Paul

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Robert DiFalco 2015-07-06 19:30:38 Re: Average New Users Per DOW
Previous Message David G. Johnston 2015-07-06 18:20:52 Re: Average New Users Per DOW