Re: Need SQL help, I'm stuck.

From: "Robert B(dot) Easter" <reaster(at)comptechnews(dot)com>
To: Chris Albertson <chrisalbertson90278(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Need SQL help, I'm stuck.
Date: 2001-12-10 23:24:07
Message-ID: 200112102324.fBANO7W04623@comptechnews.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

This seems to work:

SELECT c1,c3,c4 from (select c1, max(c2) from t1 group by c1) as dt1 (c1,c2)
natural left join t1;

Bob

> I want a SQL query that returns these rows
>
> a 3 derg hbg
> b 1 cccc rth
> c 2 derf ett
>
> All I can think of is
>
> SELECT C1, max(C2), C3, C4 FROM T1 GROUP BY C1;
>
> That does not work. What I really want is the values for C1, C3
> and C4 that are associated with the row containing the maximum
> value of C2 for each group of like C1 values. I don't even need
> to know what is max(C2).
>
> Can I join the table with itself somehow? See: "brain lock".
> This should not be hard.
>
>
> Thanks,
>
>
> =====
> Chris Albertson
> Home: 310-376-1029 chrisalbertson90278(at)yahoo(dot)com
> Cell: 310-990-7550
> Office: 310-336-5189 Christopher(dot)J(dot)Albertson(at)aero(dot)org
>
> __________________________________________________
> Do You Yahoo!?
> Send your FREE holiday greetings online!
> http://greetings.yahoo.com
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2001-12-10 23:33:59 Re: Need SQL help, I'm stuck.
Previous Message Andrew Gould 2001-12-10 23:08:37 Re: Need SQL help, I'm stuck.