Re: help with sql query

From: Richard Broersma Jr <rabroersma(at)yahoo(dot)com>
To: Peter <peterpub1(at)aboutsupport(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: help with sql query
Date: 2006-10-17 15:31:42
Message-ID: 20061017153142.65419.qmail@web31808.mail.mud.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> 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'
;

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Madison Kelly 2006-10-17 15:41:44 Re: A query planner that learns
Previous Message Scott Ribe 2006-10-17 15:30:09 Re: A query planner that learns