Re: apply limit to sum function - Mailing list pgsql-novice

From e-letter
Subject Re: apply limit to sum function
Date
Msg-id CAET1fe57E9VfxK3-AzX-XntHuM3vZ=oNTxP8H8CQ=SJOF3Q9EA@mail.gmail.com
Whole thread Raw
In response to Re: apply limit to sum function  (Steve Crawford <scrawford@pinpointresearch.com>)
Responses Re: apply limit to sum function  (Michael Wood <esiotrot@gmail.com>)
List pgsql-novice
On 27/04/2012, Steve Crawford <scrawford@pinpointresearch.com> wrote:
> On 04/27/2012 12:27 PM, e-letter wrote:
>> Readers,
>>
>>   Is it possible to apply the 'sum' function, but limit the value and
>>   then show the tuples of the result? For example, the table has:
>>
>>   text1, 10
>>   text2, 12,
>>   text3, 23
>>
>>   Instead of applying the 'sum' function to all values, the request is
>>   to be able to select those values that result in a sum of a target
>>   value (e.g.<  22) and then return the tuples.
>>
>
> select somelabel, sum(somevalue) from sometable group by somelabel
> having sum(somevalue) > yourtargetvalue;
>
...
>
>
> select * from (
> select *, sum(somevalue) over (partition by somelabel) as labelcount
> from sometable) as foo
> where labelcount > yourtargetvalue;
>

So far, tried these methods above but produced:

text1, 10
text2, 12

It seems that these queries produce a result that corresponds to _each
row_ value being evaluated against the target value. The desired
output is that the sum of the values in the result is to be evaluated
against the target. But thanks anyway so far.

pgsql-novice by date:

Previous
From: Steve Crawford
Date:
Subject: Re: apply limit to sum function
Next
From: Michael Wood
Date:
Subject: Re: apply limit to sum function