I'm trying to get the names of customers who have placed the 5 highest orders. I'm able to run one query to find the highest order, and another query to find the number of orders placed by each customer. Is there a way to combine these two queries to obtain the desired results?
Here are the queries I've developed:
SELECT CUSTOMERS.CNAME, COUNT(DISTINCT ORDERS.ONO)
FROM CUSTOMERS, ORDERS
WHERE CUSTOMERS.CNO = ORDERS.CNO
GROUP BY CUSTOMERS.CNAME;
SELECT MAX(COUNT(DISTINCT ORDERS.ONO))
FROM CUSTOMERS, ORDERS
WHERE CUSTOMERS.CNO = ORDERS.CNO
GROUP BY CUSTOMERS.CNAME;
Here are the relations I'm working with:
CUSTOMERS(CNO,CNAME,STREET,ZIP,PHONE)
ORDERS(ONO,ENO,RECEIVED,SHIPPED)
Here are the queries I've developed:
SELECT CUSTOMERS.CNAME, COUNT(DISTINCT ORDERS.ONO)
FROM CUSTOMERS, ORDERS
WHERE CUSTOMERS.CNO = ORDERS.CNO
GROUP BY CUSTOMERS.CNAME;
SELECT MAX(COUNT(DISTINCT ORDERS.ONO))
FROM CUSTOMERS, ORDERS
WHERE CUSTOMERS.CNO = ORDERS.CNO
GROUP BY CUSTOMERS.CNAME;
Here are the relations I'm working with:
CUSTOMERS(CNO,CNAME,STREET,ZIP,PHONE)
ORDERS(ONO,ENO,RECEIVED,SHIPPED)