Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 94C9B9F9837 for ; Thu, 16 Aug 2007 03:17:02 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 08726-08 for ; Thu, 16 Aug 2007 03:16:55 -0300 (ADT) X-Greylist: delayed 00:05:01.079215 by SQLgrey-1.7.5 Received: from sccrmhc14.comcast.net (sccrmhc14.comcast.net [204.127.200.84]) by postgresql.org (Postfix) with ESMTP id CB7259F97DF for ; Thu, 16 Aug 2007 03:16:56 -0300 (ADT) Received: from dominion.diehlnet.com ([76.18.87.61]) by comcast.net (sccrmhc14) with ESMTP id <200708160611530140008erue>; Thu, 16 Aug 2007 06:11:53 +0000 Received: from [10.0.1.55] by dominion.diehlnet.com with esmtp (Exim 4.67) (envelope-from ) id 1ILYa2-0008P7-KM; Thu, 16 Aug 2007 00:11:52 -0600 From: Mike Diehl To: "Fernando Hevia" Subject: Re: Problem with phone list. Date: Thu, 16 Aug 2007 00:11:36 -0600 User-Agent: KMail/1.9.7 Cc: "'SQL Postgresql List'" References: <021801c7df7f$043d8610$8f01010a@iptel.com.ar> In-Reply-To: <021801c7df7f$043d8610$8f01010a@iptel.com.ar> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200708160011.36868.jdiehl@sandia.gov> X-Spam-Score-int: -13 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/138 X-Sequence-Number: 29076 Yup, that did it. I don't know why I made it harder than it had to be. Thank you. Mike. On Wednesday 15 August 2007 02:58:22 pm Fernando Hevia wrote: > Try this: > > Select * > from view v1 > where duration =3D (select max(duration) from view v2 where v2.phone_numb= er =3D > v1.phone_number) > > You could get more than one call listed for the same number if many calls > match max(duration) for that number. > > > -----Mensaje original----- > De: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] > En nombre de Mike Diehl > Enviado el: Mi=E9rcoles, 15 de Agosto de 2007 17:28 > Para: SQL Postgresql List > Asunto: [SQL] Problem with phone list. > > Hi all. > > I've qot a problem I need to solve. I'm sure it's pretty simple; I just > can't > seem to get it, so here goes... > > I've got a table, actually a view that joins 3 tables, that contains a > phone > > number, a unique id, and a call duration. > > The phone number has duplicates in it but the unique id is unique. > > I need to get a list of distinct phone numbers and the coorisponding > largest > > call duration. > > I've got the idea that this should be a self-join on phone number where > a.id<>b.id, but I just can't seem to get the max duration. > > Any hints would be much appreciated. > > Mike. > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Have you searched our list archives? > > http://archives.postgresql.org =2D-=20 Mike Diehl