Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: using the result of a partial sum in a where clause

Re: using the result of a partial sum in a where clause

From: Rich Dillon <richdillon_at_mindspring.com>
Date: Tue, 18 Jun 2002 14:32:37 -0700
Message-ID: <pan.2002.06.18.14.32.37.384340.2379@mindspring.com>


On Tue, 18 Jun 2002 10:17:09 -0700, Adrián Garrido wrote:

> Hi
>
> I have a table like this:
>
> Date Value
> 01/01/2002 1
> 01/07/2002 3
> 01/09/2002 2
> 02/03/2002 9
> 03/10/2002 5
>
> I want to get the date in wich the sum of its asigned value and its
> predecesors is greater or equal than a supplied parameter. For example,
> if the parameter = 5, the query should return 01/09/2002, (1 + 3 + 2 >
> 5).
>
> It can be done easily with a explicit cursor but, can a standard sql
> query be used?
>
> Thanks in advance
> Adrián Garrido

SELECT MIN(datecol)
FROM (
  SELECT F1.datecol
  FROM foo F1, foo F2
  WHERE F1.datecol >= F2.datecol
  GROUP BY F1.datecol
  HAVING SUM(F2.valuecol) >= 5); Received on Tue Jun 18 2002 - 16:32:37 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US