Re: duplicate dates

From: Jonathan Gardner <jgardner(at)jonathangardner(dot)net>
To: Jodi Kanter <jkanter(at)virginia(dot)edu>, Postgres SQL List <pgsql-sql(at)postgresql(dot)org>
Subject: Re: duplicate dates
Date: 2003-08-08 15:29:36
Message-ID: 200308080829.37711.jgardner@jonathangardner.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Friday 01 August 2003 08:56, Jodi Kanter wrote:
> I have one table that has a date/time field in it. I'd like to identify
> the records in the database where the date/time fields are the same. How
> can I do this? Do I need to create a view or temp table? Is there a way
> to run through one table multiple times.

SELECT date_trunc('month', date_column), ...
GROUP BY date_trunc('month', date_column)
HAVING count(primary_key) > 1;

Replace date_trunc('month', date_column) with whatever you want to group it
by. Note that date_part can give you interesting groupings (all the
Decembers, all the 1st of the months, all the Fridays, etc...)

If you want to run through it several times, you can have a sub-select in the
from clause. You could also save the results in a temp table.

- --
Jonathan Gardner <jgardner(at)jonathangardner(dot)net>
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE/M8HgWgwF3QvpWNwRAsUNAKCLnB6vajJ8fuS7IRgp0pYxp6YaxgCg2qbk
juL5a4tM1la0zmP81PdxS/c=
=N8Q/
-----END PGP SIGNATURE-----

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2003-08-08 15:52:30 Re: [pg-sql] - Problem with duplicate table (PostgreSQL 7.2.3
Previous Message krystoffff 2003-08-08 14:13:28 Error message with a SQL function