| От | Mark Fenbers |
|---|---|
| Тема | Aggregates puzzle |
| Дата | |
| Msg-id | 4D94E0CB.4020309@noaa.gov обсуждение исходный текст |
| Ответы |
Re: Aggregates puzzle
Re: Aggregates puzzle |
| Список | pgsql-sql |
SQL gurus, I have a table with 4 columns: lid(varchar), value(float), obstime(datetime), event_id(integer) I want to find the MAX(value) and the time and date that it occurred (obstime) in each group of rows where the lid and event_id are the same. What I have works correctly in identifying the MAX(value) for the given group, but I'm having trouble getting the corresponding obstime to be reported along with it. Here's the SQL I have: SELECT lid, MAX(value), event_id FROM flood_ts GROUP BY lid, event_id ORDER BY lid; If I add "obstime" to the SELECT list, then I need to add "value" to the GROUP BY clause, which makes the MAX(value) function report *each row* as a maximum. So, how can I revise my SQL to report the obstime that the MAX(value) occurred? Any help is sincerely appreciated. Mark
В списке pgsql-sql по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера