[GENERAL] (P)SQL for a sum with constraints

2009-04-15 Thread Shug Boabby
Hello all, I have a table with 2 bigint columns, let's call them A and B. I need a query that will allow me to return A alongside the sum of Bs from rows where A is less than or equal to this row's A. It is best described with some example data, consider the following: A B 1 0 2 1 3 0 4 2 5 1 I

Re: [GENERAL] (P)SQL for a sum with constraints

2009-04-15 Thread Shug Boabby
B C 1 0 1 2 1 1 3 1 1 4 3 1 5 4 1 1 0 2 2 1 2 3 1 2 4 3 2 5 4 2 Also... could you please explain why the syntax requires the "user_id::text" to be passed to cumulative sum? I'm confused why the "::text" part is there. 2009/4/15 hubert depesz lubaczewski : > On Wed, Apr 1

Re: [GENERAL] (P)SQL for a sum with constraints

2009-04-17 Thread Shug Boabby
, 15 Apr 2009 15:32:42 +0100, Shug Boabby wrote: >> I simplified my problem a little too much and now I'm stuck trying to >> use cumulative_sum(). My schema is not only A, B but also has a C >> >> A B C >> 1 0 1 >> 2 1 1 >> 3 0 1 >> 4 2 1 >>

Re: [GENERAL] (P)SQL for a sum with constraints

2009-04-17 Thread Shug Boabby
Oh... and also, A, B, C are in the same table. 2009/4/17 Shug Boabby : > Life sure would be easier if that were the case Michal, but no... that > is not the case here. The sum is not a simple sum, it is a sum of all > elements having a lower or equal A and the same C. This is a > &qu

Re: [GENERAL] (P)SQL for a sum with constraints

2009-04-17 Thread Shug Boabby
Michal... I must apologise, your suggestion worked a treat!!! I never realised it was possible to do a join on a table to itself before! 2009/4/15 Michal Politowski : > On Wed, 15 Apr 2009 15:32:42 +0100, Shug Boabby wrote: >> I simplified my problem a little too much and now I'm s