Re: highest match in group
От | Arjen van der Meijden |
---|---|
Тема | Re: highest match in group |
Дата | |
Msg-id | 3FD74826.5000603@vulcanus.its.tudelft.nl обсуждение исходный текст |
Ответ на | highest match in group ("Dave [Hawk-Systems]" <dave@hawk-systems.com>) |
Ответы |
Update multiple columns with select statement?
|
Список | 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
В списке pgsql-general по дате отправления: