Embarassing GROUP question
От | Corey Tisdale |
---|---|
Тема | Embarassing GROUP question |
Дата | |
Msg-id | 36AA710D-69ED-4C8D-8F79-C3E69DB36C0E@eyewantmedia.com обсуждение исходный текст |
Ответ на | Re: Procedure for feature requests? (Martin Gainty <mgainty@hotmail.com>) |
Ответы |
Re: Embarassing GROUP question
|
Список | pgsql-general |
Hi all, I'm a recent MySQL convert, and I am having some difficulty with syntax on grouping a table by a foreign key and returning only the newest entry that matches. In MySQL, you can do something like event_log ------------ id event_type event_date meaningful_data SELECT meaningful_data, event_type, event_date FROM event_log GROUP BY event_type ORDER BY event_date DESC And this would return back the most recent event and meaningful data for each event type. When I try this in postgres, I get errors about either grouping by id or using id in an aggregate function. I am afraid if I use it in an aggregate function, it will disrupt the sort order I am attempting, and if I group by it, I no longer get the most recent data for each event type, but I get every event. How would I accomplish this is postresql? Is there some aggregate functions that help with this, or should I be trying a different method altogether? Grouping feels pretty different, and I suspect closer to standards, in postgres. Unfortunately, my mind works (for the short term) in mysql. Will someone please give me some pointers? Thanks! Corey
В списке pgsql-general по дате отправления: