Re: New to SQL

From: Richard Frazier <rfrazier_at_mailstorm.dot.gov>
Date: 1995/11/29
Message-ID: <49hi9s$je4_at_news.dot.gov>#1/1


KamiCASE (case_at_pt.hk-r.se) wrote:
: Hi !
 

: I have a problem. I'm trying to write a SQL statement to recive alla
: customers names for the 6000 best customers who has bought articels
: during 1995.
 

: My two databas tabels looks like this
 

: Customer Order
: ___________ ____________
: customerID CustomerID
: Name TotalAmount (since the customer became a customer in the system)
: OrderNumber
: ShipedDate
 

: I would be very glad if someone could help me with this.
 

: Jost Werdenhoff
: Mda94jwe_at_rby.hk-r.se

The easiest way to do this is to simply set a totalamount limit where you know you will get at least your 6000 customers, then query based on that limit. For example:

select a.name,b.totalamount
from customer a, order b
where a.customerid = b.customerid
and b.totalamount > 100000; (this assumes at least 6000 customers have totals > 100000. If you are not sure what limit to use, run some preliminary queries to help find the limit:

ex: select count(*) from order where totalamount > 100000

If the above don't work, then you may have to use something like PLSQL which will give you a looping (and thus counting) capability. Or perhaps some other ideas will be provided here in the newsgroup. Received on Wed Nov 29 1995 - 00:00:00 CET

Original text of this message