From: | "Michael Avila" <Michael(dot)Avila(dot)1(at)sbcglobal(dot)net> |
---|---|
To: | "SQL PostgreSQL MailList" <pgsql-sql(at)postgresql(dot)org> |
Subject: | Need SQL Help Finding Current Status of members |
Date: | 2005-12-16 01:31:09 |
Message-ID: | NBBBLNPHAMCFENDFHIDCGENBEGAA.Michael.Avila.1@sbcglobal.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
I have a table which keeps track of the status of members. In the table is
member_id int(8)
status_code char(1)
status_date date
KEY member_id (member_id,status_code,status_date)
Each member can have multiple records because a record is added each time
the status changes but the old record is kept for history.
What I want to do is find the latest status for each member. Actually I want
to find all those with an status of "A". But it must be the current (latest)
status. How do I find the most current date for each member in a pile of
many records for many members with many status settings with one SQL
statement? This is a bit beyond my capabilities so I am asking for help.
My initial SQL is
SELECT * FROM memberstatus WHERE status_code = 'a'
but that is my limit. I know an AND comes next but need help after that! I
know that MAX is not for dates so that is out. Is there a LATEST DATE? I did
not see one when I was looking at the date functions.
Appreciate the help.
Mike
Attachment | Content-Type | Size |
---|---|---|
winmail.dat | application/ms-tnef | 1.9 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Fuhr | 2005-12-16 02:58:52 | Re: Need SQL Help Finding Current Status of members |
Previous Message | Ken Winter | 2005-12-15 17:20:28 | Re: Defaulting a column to 'now' |