Subject Re: using ALL or ANY
Author Rick Roen
Sorry, I think my initial description was incomplete.

I need the CUSTOMER to have ALL Sum(O.Total) by SEASON to be over 1000

or

not ANY Sum(O.Total) by SEASON < 1000

The query below returns the same customer multiple times if any of
their SEASON totals > 1000.

I thought about trying to do a MIN(SUM(O.Total)) > 1000 but I get a
message about not being able to nest aggregate functions.

Rick


--- In firebird-support@yahoogroups.com, "Nick Upson"
<nick.upson@...> wrote:
>
> Select C.IDNUM, O.SEASON, Sum(O.TOTAL)
> from CUSTOMERS C
> inner join ORDERS O on O.CUSTNUM = C.IDNUM
> group by C.IDNUM. O.SEASON
> having Sum(O.TOTAL) > 1000
>
>
> On 24/01/07, Rick Roen <rick@...> wrote:
> > FB 1.5.3
> >
> > I need some SQL help.
> >
> > I need to qualify customers that have sales of over 1000 in
a "SEASON"
> > which is a field in the ORDERS table.
> >
> > My simplified SQL:
> >
> > Select C.*
> > from CUSTOMERS C
> > where 1000 > ALL(Select Sum(O.TOTAL) from ORDERS O where
O.CUSTNUM =
> > C.IDNUM Group by O.SEASON)
> >
> > but this is returning Customers that do not even have one sales,
much
> > less all SEASON's sales over 1000.
> >
> > Can someone shed some light on how to do this?
> >
> > Rick
> >
>