From: | Arjen van der Meijden <acmmailing(at)vulcanus(dot)its(dot)tudelft(dot)nl> |
---|---|
To: | "Dave [Hawk-Systems]" <dave(at)hawk-systems(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: highest match in group |
Date: | 2003-12-10 16:21:58 |
Message-ID: | 3FD74826.5000603@vulcanus.its.tudelft.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Dave [Hawk-Systems] wrote:
> have a data table that records entries by date(unix timestamp) and customer
> number. each custnum will have several entries showing a running ledger type
> snapshot. we have the need to get the most recent entry from not one, but all
> unique customers, in the most cost effective manner.
>
> [snip]
>
> Currently we are running through all our customer numbers in one query, then
> for each customer number querying the summary table to get each customers
> latest entry (select order by date desc limit 1). Obviously this results in a
> large number of queries and is expensive. Looking for a more concise, less
> expensive way.
>
> thanks
>
> Dave
What about something like:
SELECT so.* FROM summary so, (SELECT custnum, MAX(date) as date FROM
summary si GROUP BY custnum) as cd WHERE so.date = cd.date AND
so.custnum = cd.custnum
Best regards,
Arjen van der Meijden
From | Date | Subject | |
---|---|---|---|
Next Message | brew | 2003-12-10 16:22:55 | Re: PostgreSQL Training |
Previous Message | Dave [Hawk-Systems] | 2003-12-10 16:08:12 | highest match in group |