select just the top

R

Rodolfo Fontes

Hi group,

I have a querie that returns all sold products (total) form my companie, and
i've made a graph from it.
The trouble is that are too many products (about 2000) and i wanna set up
just the top 10 sellers.
How can i do that?

Thanks,
Rodolfo Fontes
 
J

Jamie Richards

I'll have a stab at it:

Caution air code:

SELECT TOP 10 P.ProductName, COUNT( OD.Quantity) AS [Quantity Sold]
FROM tblProducts AS P INNER JOIN tblOrderDetails ON
P.ProductID = OD.ProductID
GROUP BY P.ProductName
ORDER BY OD.Quantity DESC

With any luck this will rank the records in descending order on the order
quantity. If you want a percentage returned (say top 10%, try adding the
PERCENT keyword after the number like so: SELECT TOP 10 PERCENT ...).

Make sure you check it, I don't do this often :blush:)#)

Good luck!

Jamie
 
R

Rodolfo Fontes

Thanks a lot Jamie!
i don't believe it was simple like that!


Jamie Richards said:
I'll have a stab at it:

Caution air code:

SELECT TOP 10 P.ProductName, COUNT( OD.Quantity) AS [Quantity Sold]
FROM tblProducts AS P INNER JOIN tblOrderDetails ON
P.ProductID = OD.ProductID
GROUP BY P.ProductName
ORDER BY OD.Quantity DESC

With any luck this will rank the records in descending order on the order
quantity. If you want a percentage returned (say top 10%, try adding the
PERCENT keyword after the number like so: SELECT TOP 10 PERCENT ...).

Make sure you check it, I don't do this often :blush:)#)

Good luck!

Jamie

Rodolfo Fontes said:
Hi group,

I have a querie that returns all sold products (total) form my companie,
and
i've made a graph from it.
The trouble is that are too many products (about 2000) and i wanna set up
just the top 10 sellers.
How can i do that?

Thanks,
Rodolfo Fontes
 
J

Jamie Richards

Everything's simple when you have a guess. See if it works before you get
too excited! ;o)

Jamie


Rodolfo Fontes said:
Thanks a lot Jamie!
i don't believe it was simple like that!


Jamie Richards said:
I'll have a stab at it:

Caution air code:

SELECT TOP 10 P.ProductName, COUNT( OD.Quantity) AS [Quantity Sold]
FROM tblProducts AS P INNER JOIN tblOrderDetails ON
P.ProductID = OD.ProductID
GROUP BY P.ProductName
ORDER BY OD.Quantity DESC

With any luck this will rank the records in descending order on the order
quantity. If you want a percentage returned (say top 10%, try adding the
PERCENT keyword after the number like so: SELECT TOP 10 PERCENT ...).

Make sure you check it, I don't do this often :blush:)#)

Good luck!

Jamie

Rodolfo Fontes said:
Hi group,

I have a querie that returns all sold products (total) form my
companie,
and
i've made a graph from it.
The trouble is that are too many products (about 2000) and i wanna set up
just the top 10 sellers.
How can i do that?

Thanks,
Rodolfo Fontes
 
J

Jamie Richards

Actually, you know, it won't work! I left an alias of the OrderDetails
table.

Use the copy below instead:

SELECT TOP 10 P.ProductName, COUNT( OD.Quantity) AS [Quantity Sold]
FROM tblProducts AS P INNER JOIN tblOrderDetails AS OD ON
P.ProductID = OD.ProductID
GROUP BY P.ProductName
ORDER BY OD.Quantity DESC


Jamie

Rodolfo Fontes said:
Thanks a lot Jamie!
i don't believe it was simple like that!


Jamie Richards said:
I'll have a stab at it:

Caution air code:

SELECT TOP 10 P.ProductName, COUNT( OD.Quantity) AS [Quantity Sold]
FROM tblProducts AS P INNER JOIN tblOrderDetails ON
P.ProductID = OD.ProductID
GROUP BY P.ProductName
ORDER BY OD.Quantity DESC

With any luck this will rank the records in descending order on the order
quantity. If you want a percentage returned (say top 10%, try adding the
PERCENT keyword after the number like so: SELECT TOP 10 PERCENT ...).

Make sure you check it, I don't do this often :blush:)#)

Good luck!

Jamie

Rodolfo Fontes said:
Hi group,

I have a querie that returns all sold products (total) form my
companie,
and
i've made a graph from it.
The trouble is that are too many products (about 2000) and i wanna set up
just the top 10 sellers.
How can i do that?

Thanks,
Rodolfo Fontes
 
R

Rodolfo Fontes

Yes, it works fine!

Jamie Richards said:
Everything's simple when you have a guess. See if it works before you get
too excited! ;o)

Jamie


Rodolfo Fontes said:
Thanks a lot Jamie!
i don't believe it was simple like that!


Jamie Richards said:
I'll have a stab at it:

Caution air code:

SELECT TOP 10 P.ProductName, COUNT( OD.Quantity) AS [Quantity Sold]
FROM tblProducts AS P INNER JOIN tblOrderDetails ON
P.ProductID = OD.ProductID
GROUP BY P.ProductName
ORDER BY OD.Quantity DESC

With any luck this will rank the records in descending order on the order
quantity. If you want a percentage returned (say top 10%, try adding the
PERCENT keyword after the number like so: SELECT TOP 10 PERCENT ...).

Make sure you check it, I don't do this often :blush:)#)

Good luck!

Jamie

Hi group,

I have a querie that returns all sold products (total) form my
companie,
and
i've made a graph from it.
The trouble is that are too many products (about 2000) and i wanna
set
up
just the top 10 sellers.
How can i do that?

Thanks,
Rodolfo Fontes
 

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

order on the months. 4
Pass a parameter by code. 5
access is rounding a value 9
formating a text value 2
Types of JOIN 2
Parameterizing a SELECT TOP x statement 4
Count on the page 1
form criteria 4

Top