From: Larry Rosenman <ler@lerctr.org>
To: pgsql-sql@postgresql.org
Subject: Can I simplify this somehow?
Date: Fri, 27 Sep 2013 10:22:09 -0500
Message-ID: <4d75971ff9afefca1f715960b59ef986@webmail.lerctr.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>
I tried(!) to write this as a with (CTE), but failed.
Can one of the CTE experts (or better SQL writer) help me here?
-- generate a table of timestamps to match against
select
generate_series(date_trunc('day',now()-'45 days'::interval),now()+'1
hour'::inte
rval,'1 hour')
AS thetime into temp table timestamps;
-- get a count of logged in users for a particular time
SELECT thetime,case extract(dow from thetime)
when 0 then 'Sunday'
when 1 then 'Monday'
when 2 then 'Tuesday'
when 3 then 'Wednesday'
when 4 then 'Thursday'
when 5 then 'Friday'
when 6 then 'Saturday' end AS "Day", count(*) AS
"#LoggedIn"
FROM timestamps,user_session
WHERE thetime BETWEEN login_time AND COALESCE(logout_time, now())
GROUP BY thetime
ORDER BY thetime;
Thanks for any help at all.
--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 214-642-9640 (c) E-Mail: ler@lerctr.org
US Mail: 108 Turvey Cove, Hutto, TX 78634-5688
--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
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: ler@lerctr.org
Subject: Re: Can I simplify this somehow?
In-Reply-To: <4d75971ff9afefca1f715960b59ef986@webmail.lerctr.org>
* 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