select just the top

  • Thread starter Thread starter Rodolfo Fontes
  • Start date Start date
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
 
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 :o)#)

Good luck!

Jamie
 
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 :o)#)

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
 
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 :o)#)

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
 
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 :o)#)

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
 
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 :o)#)

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
 
Back
Top