Grouping question.

Поиск
Список
Период
Сортировка
От Michael J Schout
Тема Grouping question.
Дата
Msg-id 199805270445.XAA23195@mail.gkg-com.com
обсуждение исходный текст
Список pgsql-sql
Hi.

I have a problem doing a query that I think should be simple, but I dont
see the simple answer here.

The table looks like this:

CREATE TABLE mdata (
  ts timestamp default now(),
  city text,
  data float );

What I want to get is the most up to date "data" for each city (IE the data
for each city whose timestamp is the highest).  I can get the highest
timestamp, and city name with:

select max(datetime(ts)), city from mdata group by city;

but what I really want is:

select max(datetime(ts)), city, data from mdata group by city,
max(datetime(ts));

(ie I want the data field too, not just the city names).

Does anyone know of a simple solution to this, or even a complex one? The
only other think I can think of to do is select the max ts, city, then do a
query for each row of that result (yuck!!).

Thanks

Mike

В списке pgsql-sql по дате отправления:

Предыдущее
От: guenther@laokoon.in-berlin.de (Christian Guenther)
Дата:
Сообщение: how to compile and use soundex
Следующее
От: Przemyslaw Bak
Дата:
Сообщение: ...