From: | "Albe Laurenz" <all(at)adv(dot)magwien(dot)gv(dot)at> |
---|---|
To: | "Richard Broersma Jr *EXTERN*" <rabroersma(at)yahoo(dot)com>, "Peter" <peterpub1(at)aboutsupport(dot)com>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: help with sql query |
Date: | 2006-10-18 08:08:26 |
Message-ID: | 52EF20B2E3209443BC37736D00C3C1380AE75ED3@EXADV1.host.magwien.gv.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Richard Broersma Jr wrote:
>> id id_1 id_2 date_time
>> 1 101 1000 2006-07-04 11:25:43
>> I want to find all records have same id_1, but different id_2 and
have
>> difference in time less than 5 minutes.
>> In this case this is record 1 and record 3.
>> How can I do this ?
>
> I am sure that this will need some "tuning" to get it to work
> correctly but should give you one
> way to get what you want.
>
> select a.id, a.id_1, a.id_2, a.date_time
>
> from table1 a join table1 b on (a.id_1 = b.id_1)
> where
> a.id_2 != b.id_2
> and
> abs( a.date_time - b.date_time) < ' 5 minutes'
> ;
... maybe use 'a.id_2 < b.id_2' if you want to exclude double results.
Yours,
Laurenz Albe
From | Date | Subject | |
---|---|---|---|
Next Message | Najib Abi Fadel | 2006-10-18 08:14:08 | Moving postgres users accounts from one postgres 7.3 to postgres 8.0 |
Previous Message | J S B | 2006-10-18 08:05:40 | Urgen help required |