Skip site navigation (1) Skip section navigation (2)

Re: sum() over (partition by order) question

From: "Jaime Casanova" <jcasanov(at)systemguards(dot)com(dot)ec>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: sum() over (partition by order) question
Date: 2008-12-31 22:26:39
Message-ID: 3073cc9b0812311426i7335201aqee10345043c1f460@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-hackers
On Wed, Dec 31, 2008 at 4:34 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Hello
>
> I am play with windows function. I was surprised so these queries has
> different results.
>
> postgres=# select sum(a) over (partition by b), a, b from foo;

AFAIUI, this means one sum per b value, the result in the sum column
will be equivalent to "select sum(a) from foo group by b"

>
> postgres=# select sum(a) over (partition by b order by a), a, b from foo;

and this means something like accumulate the value of a per b value
and for every value of b accumulate per a value... maybe this can be
described better...

don't know exactly if we can imitate this behaviour without window functions

-- 
Atentamente,
Jaime Casanova
Soporte y capacitación de PostgreSQL
Asesoría y desarrollo de sistemas
Guayaquil - Ecuador
Cel. +59387171157

In response to

pgsql-hackers by date

Next:From: Tom LaneDate: 2008-12-31 22:57:45
Subject: Re: sum() over (partition by order) question
Previous:From: Pavel StehuleDate: 2008-12-31 22:19:14
Subject: Re: sum() over (partition by order) question

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group