Re: Query question.

From: Peter <yabing.bi_at_ncr.com>
Date: Thu, 6 Dec 2001 13:27:10 -0800
Message-ID: <3c0fe2af_at_rpc1284.daytonoh.ncr.com>


Matt,

Thanks for the quick reply. Your query works fine itself, but I can't use sum(OrderAmount) in 'where' clause to select customers who have more than certain number of sum(OrderAmount).

Any suggestions?

Thanks,
Peter

"Matthew D. Bennett" <mbennett_at_utah-inter.net> wrote in message news:3C0FC8A6.1B7248DE_at_utah-inter.net...
> Peter,
>
> Try the following SELECT statement:
>
> SELECT customerID, sum(OrderAmount)
> FROM TABLENAME
> GROUP BY CustomerID;
>
> Matt.
>
>
>
> Peter wrote:
> >
> > Hi,
> >
> > Say I have a table with OrderID, CustomerID and OrderAmount (and more
item)
> > with OrderID as pk, each customer(CustomerID) can have more than one
orders,
> > if I want to get the list of (distinct) CustomerID and OrderAmount which
the
> > accumulated OrderAmount for that customer is more than a certain number,
> > what the query should be?
> >
> > Sample table:
> >
> > OrderID CustomerID OrderAmount
> > --------- ------------ --------------
> > 1 100 10
> > 2 101 9
> > 3 100 6
> > 4 102 13
> > 5 101 11
> > .....
> >
> > I want output of:
> >
> > CustomerID Total OrderAmount
> > ------------ ---------------------
> > 100 16
> > 101 20
> > 102 13
> > ....
> >
> > Thanks,
> > Barry
>
Received on Thu Dec 06 2001 - 22:27:10 CET

Original text of this message