LIST QUERY PROBLEM

  • Thread starter jonathan.cohen150887
  • Start date
J

jonathan.cohen150887

Hi,

Ok I have written up the following query which basically asks : list
everyone who has bought two or more books by the same author.

I have the following table schemas:

CustomerOrders_Bookstock {Customer order reference, ISBN reference,
Packaging date, Shipping date, Quantity}

Customer orders {Customer order reference#, Customer reference,
Shipping address reference, Order Date, Delivery method reference,
Total amount owed}

Book_Authors {ISBN reference, Author reference}

SO i have to come up with a list of customer reference in the end.

I have the following:

SELECT CUSTOMERS.Customer_ref, CUSTOMERS.C_FNAME, CUSTOMERS.C_LNAME,
CustomerOrders.CustOrder_ref, Authors.Author_ref, Authors.AUT_FNAME,
Authors.AUT_LNAME, COUNT(CustOrders_Books.Quantity) AS
Number_of_copies_bought, COUNT(Authors.Author_ref) AS
Number_of_titles_bought
FROM Customers, CustomerOrders, Authors, CustOrders_Books
WHERE CUSTOMERS.Customer_ref = CustomerOrders.Customer_ref
AND CustomerOrders.CustOrder_ref = CustOrders_Books.CustOrder_ref
AND CustOrders_Books.ISBN_Ref = Book_Author.ISBN_Ref
AND Book_Author.Author_Ref = Author.Author_Ref
GROUP BY Customers.Customer_Ref, Customers.C_FNAME,
CustomerOrders.CustOrder_ref, Author.Author_Ref, Authors.AUT_LNAME,
Authors.AUT_FNAME
HAVING COUNT(CustOrders_Books.Quantity) >=2
AND (Author.Author_Ref) >=2;

The problem is the way it was written means that we have to enter an
author_ref ourselves meaning that its for a specific author, but I
would like that query to work on every author and come up with the
list of customer references without me having to input a specific
author ref.

Can anyone help me?

thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top