pgsql aggregate: conditional max

Поиск
Список
Период
Сортировка
От Weimao Ke
Тема pgsql aggregate: conditional max
Дата
Msg-id 4413AD1C.9050604@indiana.edu
обсуждение исходный текст
Ответы Re: pgsql aggregate: conditional max  (Jeffrey Melloy <jmelloy@visualdistortion.org>)
Re: pgsql aggregate: conditional max  (Michael Fuhr <mike@fuhr.org>)
Re: pgsql aggregate: conditional max  (Daniel CAUNE <d.caune@free.fr>)
Список pgsql-sql
Hi,

I need a special aggregation function. For instance, given the following 
table data:
  aid    |   cat   | weight
----------+---------+---------a1  | Drama   |       1a1  | Romance |       6a1  | Short   |       1a1 | Other   |
7a2 | Comedy  |       1a2 | Drama   |       2a3  | Drama   |       1a3 | Adult   |       2a3 | Comedy  |       1a3 |
Other  |       1
 

I want to group by "aid" and choose the category (i.e., "cat") with the 
largest "weight":

aid   |   max_weighted_cat
----+---------------------
a1   |   Other
a2   |   Drama
a3   |   Adult

Any ideas? Thank you! :)

-- 
All best, 

Weimao

Weimao Ke
Indiana University Bloomington
School of Library and Information Science
http://ella.slis.indiana.edu/~wke



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

Предыдущее
От: Christopher Browne
Дата:
Сообщение: Re: Merging rows into one result?
Следующее
От: Jeffrey Melloy
Дата:
Сообщение: Re: pgsql aggregate: conditional max