pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: reb_01501@yahoo.com
To: pgsql-sql@postgresql.org
Subject: Re: Simple Query HELP!!!
Date: Sun, 23 Sep 2001 03:12:12 GMT
Message-ID: <3bad5086.29922681@news.charter.net> (raw)
References: <a27df63d.0109221818.2347f039@posting.google.com>

On 22 Sep 2001 19:18:10 -0700, bulk@colonnello.org (Paolo Colonnello)
wrote:

>Hello, I have the following, A table call People with 3 fields AGE
>(Int) NAME (Txt) COMPANY (TxT) and I want to create a query than get
>me a list with the seniors per company, for example :
>
>table PEOPLE
>
>NAME   AGE   COMPANY
>Bob     33      Acme
>Jane    30      Acme
>Bill    20      Acme
>Jose    56     ATech
>Siu     40     ATech
>Paolo   28       IBM
>Maria   38       IBM
>
>I need a query than will return a list with the seniors per company
>like
>
>Bob
>Jose
>Maria
>
>Is there a way to do this with one query?
>
Do you care about ties? What if Ingrid, 38 yrs old, worked at IBM?
Would you want to show both Ingrid and Maria? If so, this will work:

Select Name From People t1 Inner Join
(Select Company, Max(Age) As Oldest FROM People
Group By Company) t2
ON t1.Company = t2.Company  AND t1.Age = t2.Oldest 

HTH,
Bob Barrows
Please reply to the newsgroup. My reply-to address is my "spam trap" and I don't check it very often.



view thread (5+ messages)  latest in thread

Message-ID: <3bad5086.29922681@news.charter.net>
Permalink:  ../3bad5086.29922681@news.charter.net/
Also on:    postgresql.org/message-id/3bad5086.29922681@news.charter.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: reb_01501@yahoo.com
  Subject: Re: Simple Query HELP!!!
  In-Reply-To: <3bad5086.29922681@news.charter.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox