Re: max timestamp

From: Robert Creager <Robert_Creager(at)LogicalChaos(dot)org>
To: stermic(at)gw(dot)co(dot)jackson(dot)mo(dot)us (Michael Sterling)
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: max timestamp
Date: 2004-02-15 20:00:25
Message-ID: 20040215130025.4e74ebf1.Robert_Creager@LogicalChaos.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

--Multipart_Sun__15_Feb_2004_13_00_25_-0700_=.9v9EXutjLmb9oy
Content-Type: text/plain; charset=US-ASCII
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

When grilled further on (10 Feb 2004 10:14:04 -0800),
stermic(at)gw(dot)co(dot)jackson(dot)mo(dot)us (Michael Sterling) confessed:

> i'm trying to get the max time stamp, from each day, of a range of
> dates, not just the max time stamp for the complete range dates but
> for each day.
>

Well, one gross and ugly way is:

SELECT MAX( "when" ) FROM readings, (SELECT DATE_TRUNC( 'day', "when" ) AS
period FROM readings GROUP BY period) AS p WHERE DATE_TRUNC( 'day', "when" ) =
p.period GROUP BY p.period;

given the table readings looks something like:

CREATE TABLE readings
(
"when" TIMESTAMP DEFAULT timeofday()::timestamp
NOT NULL PRIMARY KEY
);

I'm curious to see other, 'better' solutions.

Cheers,
Rob

--
12:52:57 up 20:36, 2 users, load average: 2.08, 2.17, 2.18
Linux 2.4.21-0.13_test #60 SMP Sun Dec 7 17:00:02 MST 2003

--Multipart_Sun__15_Feb_2004_13_00_25_-0700_=.9v9EXutjLmb9oy
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iEYEARECAAYFAkAvz98ACgkQLQ/DKuwDYzkKPACfXQSPtclOmvynZqNkJni8JaN8
rMkAniko3AXdzIAMNJK1Cq9P/Nk+90+5
=ODLo
-----END PGP SIGNATURE-----

--Multipart_Sun__15_Feb_2004_13_00_25_-0700_=.9v9EXutjLmb9oy--

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tomasz Myrta 2004-02-15 20:01:37 Re: max timestamp
Previous Message Tomasz Myrta 2004-02-15 19:53:44 Re: writing a dynamic sql