G
Guest
in my simple table, each row represents a sale. among the fields, are the
id# and the state.
id# state
2 OH
2 MI
3 MI
6 RI
2 OH
2 MI
3 RI
1 RI
1 OH
I need a query to list top 5 sales by id# by state.
So far, I am doing basically this:
SELECT state, id#, count(id#)
from TABLE
GROUP BY state, id#
to get the # sales by id# and by state; or
SELECT TOP 5 state, id#, count(id#)
from TABLE
WHERE state = parameter
group by state, id#
to get the top 5 for a given state, but I cannot seem to figure out how to
generate a list of the top 5 for each state.
Thanks for any help
[hope this isn't a duplicate--my last post seemed to fail]
id# and the state.
id# state
2 OH
2 MI
3 MI
6 RI
2 OH
2 MI
3 RI
1 RI
1 OH
I need a query to list top 5 sales by id# by state.
So far, I am doing basically this:
SELECT state, id#, count(id#)
from TABLE
GROUP BY state, id#
to get the # sales by id# and by state; or
SELECT TOP 5 state, id#, count(id#)
from TABLE
WHERE state = parameter
group by state, id#
to get the top 5 for a given state, but I cannot seem to figure out how to
generate a list of the top 5 for each state.
Thanks for any help
[hope this isn't a duplicate--my last post seemed to fail]