Highest occurrence of a value from a list

  • Thread starter Thread starter tsison7
  • Start date Start date
T

tsison7

I have a query which filters out orders of a certain item. This item is
ordered in varying quantities and I want to determine which quantity is
usually ordered (ie. highest occurence of that quantity). How would I do
this?

Thanks,
 
Di,

dmax seems to only give you the maximum value of a given domain. I want to
find the qty in my table or query that shows up the most times. For instance,

ship date qty
1/1/08 5
1/2/08 10
1/3/08 5
1/4/08 5

I want to show that most orders are for a quantity of 5.

Thanks,
 
Try This:

SELECT Qty AS MostFrequentQty
FROM YourTable
GROUP BY Qty
HAVING COUNT(*) =
(SELECT MAX(QtyCount)
FROM
(SELECT COUNT(*) As QtyCount
FROM YourTable
GROUP BY Qty));

It should also find ties.

Ken Sheridan
Stafford, England
 

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

Similar Threads


Back
Top