Andres wrote:
> Hello everyone,
> I have two sql server 2000 db tables with the following fields in each:
> 
> orders=====
> orderid 
> customerid 
> orderdate
> orderamt
> 
> customers========
> customerid 
> fname
> lname
> 
> how can i query the total amount (sum(orderamt)) purchased by customers 
> who placed THEIR FIRST ORDER in a given time period? I have been 
> successfull in getting this info for customers who have placed ONE OF 
> THEIR ORDERS in a time period, but i do not know how to get the first 
> order for each customer. 

Try:

SELECT SUM(custamt)
FROM custtotal AS (
        SELECT SUM(orderamt) as custamt
        FROM orders
        GROUP BY customerid
        HAVING MIN(orderdate) BETWEEN #startdate# AND #enddate#
        )

Jochem
______________________________________________________________________
Why Share?
  Dedicated Win 2000 Server � PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionc
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to