Re: duplicate dates - Mailing list pgsql-sql

From Jonathan Gardner
Subject Re: duplicate dates
Date
Msg-id 200308080829.37711.jgardner@jonathangardner.net
Whole thread Raw
In response to duplicate dates  (Jodi Kanter <jkanter@virginia.edu>)
List 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@jonathangardner.net>
Live Free, Use Linux!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

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


pgsql-sql by date:

Previous
From: BenLaKnet
Date:
Subject: [pg-sql] - Problem with duplicate table (PostgreSQL 7.2.3
Next
From: Stephan Szabo
Date:
Subject: Re: [pg-sql] - Problem with duplicate table (PostgreSQL 7.2.3