Re: Help with SQL statement - Thanks

From: "James Orr" <james(at)lrgmail(dot)com>
To: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Help with SQL statement - Thanks
Date: 2001-07-16 18:31:30
Message-ID: 009b01c10e25$9a625940$1600000a@lrg.office
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

SELECT * FROM Payments P1 WHERE Date = (SELECT MAX(Date) FROM Payments P2
WHERE P2.CustomerNo = P1.CustomerNo)

I think that will do it.
- James

----- Original Message -----
From: "Henry" <henry_lu(at)hotmail(dot)com>
To: <pgsql-general(at)postgresql(dot)org(dot)pgsql-sql@postgresql.org>
Sent: Saturday, July 14, 2001 3:16 PM
Subject: [SQL] Help with SQL statement - Thanks

> There is a table called "Payments" which records every payment that a
> company has received:
>
> CustomerNo Date Amount
> ----------------------------------------
> 3214 2/12 30
> 3214 4/10 50
> 9943 4/18 40
> 9943 5/10 30
> 9943 2/13 70
> 1121 5/23 10
> 1121 4/20 40
> 1121 3/12 30
> (more data...)
>
>
> I want to be able to pull out the last payment made by everyone in a
query:
>
> CustomerNo Date Amount
> ---------------------------------------
> 3214 4/10 50
> 9943 5/10 30
> 1121 5/23 10
> (other users...)
>
> How should I write the SQL statement? Please email to me at
> henry_lu(at)hotmail(dot)com(dot) Thank you very much.
>
> Henry
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Peter Eisentraut 2001-07-16 20:52:52 Re: interpreting attributes in pg_class
Previous Message Bruce Momjian 2001-07-16 14:40:08 Re: Hey! ORDER BY in VIEWS?