I have one table that shows customer_name, item, qty_billed.
I'm trying to return the top 10 items billed to each customer based on summing the qty_billed.
Here's what I have based on danvlas' May 13, 2003 thread where he gives this syntax:
"Select * From [My table] As A
Where Mytotal In
(Select Top 20 MyTotal
From [My table])
Where [Cust#] = A.[Cust#])"
SELECT
[2002 billing history].CUSTOMER_NAME,
[2002 billing history].ITEM,
Sum([2002 billing history].QUANTITY_INVOICED) AS sumOfQUANTITY_INVOICED
FROM [2002 billing history]
WHERE (SELECT TOP 10 Sum([2002 billing history].QUANTITY_INVOICED) from [2002 billing history])
GROUP BY [2002 billing history].CUSTOMER_NAME,
[2002 billing history].ITEM,
ORDER BY [2002 billing history].CUSTOMER_NAME,
[2002 billing history].ITEM,
Sum([2002 billing history].QUANTITY_INVOICED) DESC;
This does not limit the returned records to the top 10, it returns all of the items and their summed qty billed for each customer. How do I get only the top 10 per customer?
I'm trying to return the top 10 items billed to each customer based on summing the qty_billed.
Here's what I have based on danvlas' May 13, 2003 thread where he gives this syntax:
"Select * From [My table] As A
Where Mytotal In
(Select Top 20 MyTotal
From [My table])
Where [Cust#] = A.[Cust#])"
SELECT
[2002 billing history].CUSTOMER_NAME,
[2002 billing history].ITEM,
Sum([2002 billing history].QUANTITY_INVOICED) AS sumOfQUANTITY_INVOICED
FROM [2002 billing history]
WHERE (SELECT TOP 10 Sum([2002 billing history].QUANTITY_INVOICED) from [2002 billing history])
GROUP BY [2002 billing history].CUSTOMER_NAME,
[2002 billing history].ITEM,
ORDER BY [2002 billing history].CUSTOMER_NAME,
[2002 billing history].ITEM,
Sum([2002 billing history].QUANTITY_INVOICED) DESC;
This does not limit the returned records to the top 10, it returns all of the items and their summed qty billed for each customer. How do I get only the top 10 per customer?