Re: Create custom aggregate function and custom sfunc

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: Create custom aggregate function and custom sfunc
Дата
Msg-id 407d949e0907021421qb1df8b1o9468f343298f08dd@mail.gmail.com
обсуждение исходный текст
Ответ на Create custom aggregate function and custom sfunc  (Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>)
Ответы Re: Create custom aggregate function and custom sfunc  (nha <lyondif02@free.fr>)
Список pgsql-sql
On Thu, Jul 2, 2009 at 3:48 PM, Jasmin
Dizdarevic<jasmin.dizdarevic@gmail.com> wrote:
> customer ; seg
> 111 ; L1
> 111 ; L2
> 111 ; L1
> 222 ; L3
> 222 ; L3
> 222 ; L2
>
> the result should look like this:
>
> 111: L1 - because L1 is higher than L2 and ratio of L1 : L2 is 2 : 1
> 222: L3 - because L3 is higher than L2 and ratio of L3 : L2 is 2 : 1

Are you just looking for the most frequent seg for each customer?

select distinct on (customer) customer,seg  from (select customer, seg, count(*) as n from tab group by seg) order by
customer,n desc 

That doesn't give the ratios though.

--
greg
http://mit.edu/~gsstark/resume.pdf


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

Предыдущее
От: justin
Дата:
Сообщение: Re: Create custom aggregate function and custom sfunc
Следующее
От: nha
Дата:
Сообщение: Re: Create custom aggregate function and custom sfunc