Re: Problem with phone list.

From: "Fernando Hevia" <fhevia(at)ip-tel(dot)com(dot)ar>
To: "'Mike Diehl'" <jdiehl(at)sandia(dot)gov>, "'SQL Postgresql List'" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Problem with phone list.
Date: 2007-08-15 20:58:22
Message-ID: 021801c7df7f$043d8610$8f01010a@iptel.com.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Try this:

Select *
from view v1
where duration = (select max(duration) from view v2 where v2.phone_number =
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(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org]
En nombre de Mike Diehl
Enviado el: Miércoles, 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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Broersma Jr 2007-08-15 21:00:05 Re: Problem with phone list.
Previous Message Rodrigo De León 2007-08-15 20:49:25 Re: Problem with phone list.