Ranking and restarting the rank on new product

M

Mike M

I'm trying to rank row in a query. I want to get the top 25 for each product
based on dollars.
e.i.

product sales rank
apples 10.00 1
apples 11.00 2
oranges 10.00 1
Bananas 10.00 1
Bananas 11.00 2

etc.

I'm using the following expression:
Rank: (Select Count (*) from T:OpportunitiesReport where [Extended
Cost]>[T:OpportunitiesReport1].[Extended Cost]+1;)

and can not figure our how to restart the count for each new product in the
query.

Can some on help me?
 
T

Tom Ellison

Dear Mike:

You need to correlate the subquery on product:

Rank: (Select Count (*) from T:OpportunitiesReport
where T.product = OpportunitiesReport.product
AND [Extended Cost]>[T:OpportunitiesReport1].[Extended Cost]+1)

That is, limit the COUNT() to those with the same product value.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Tue, 19 Oct 2004 22:05:07 -0700, Mike M <Mike
 
M

Mike M

How do I create a subquery? Do I place it in my existing query and if so how?

Tom Ellison said:
Dear Mike:

You need to correlate the subquery on product:

Rank: (Select Count (*) from T:OpportunitiesReport
where T.product = OpportunitiesReport.product
AND [Extended Cost]>[T:OpportunitiesReport1].[Extended Cost]+1)

That is, limit the COUNT() to those with the same product value.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Tue, 19 Oct 2004 22:05:07 -0700, Mike M <Mike
I'm trying to rank row in a query. I want to get the top 25 for each product
based on dollars.
e.i.

product sales rank
apples 10.00 1
apples 11.00 2
oranges 10.00 1
Bananas 10.00 1
Bananas 11.00 2

etc.

I'm using the following expression:
Rank: (Select Count (*) from T:OpportunitiesReport where [Extended
Cost]>[T:OpportunitiesReport1].[Extended Cost]+1;)

and can not figure our how to restart the count for each new product in the
query.

Can some on help me?
 
T

Tom Ellison

Dear Mike:

The thing you originally posted IS a subquery. A subquery is a query
embedded within your SQL statement. Your Rank column does just this.
All I did was to change the correlation of it to your outer (main)
query to rely on the product column being the same for each count
made.

I'm not too sure about the exact syntax you need. If you have any
problem, please post the entire SQL of your query here, not just the
one column. This may be necessary for me to help make it work
properly.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


How do I create a subquery? Do I place it in my existing query and if so how?

Tom Ellison said:
Dear Mike:

You need to correlate the subquery on product:

Rank: (Select Count (*) from T:OpportunitiesReport
where T.product = OpportunitiesReport.product
AND [Extended Cost]>[T:OpportunitiesReport1].[Extended Cost]+1)

That is, limit the COUNT() to those with the same product value.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


On Tue, 19 Oct 2004 22:05:07 -0700, Mike M <Mike
I'm trying to rank row in a query. I want to get the top 25 for each product
based on dollars.
e.i.

product sales rank
apples 10.00 1
apples 11.00 2
oranges 10.00 1
Bananas 10.00 1
Bananas 11.00 2

etc.

I'm using the following expression:
Rank: (Select Count (*) from T:OpportunitiesReport where [Extended
Cost]>[T:OpportunitiesReport1].[Extended Cost]+1;)

and can not figure our how to restart the count for each new product in the
query.

Can some on help me?
 
M

Mike M

Tom,

Thanks, messed around with it and it works.

Thanks,

Mike


Tom Ellison said:
Dear Mike:

The thing you originally posted IS a subquery. A subquery is a query
embedded within your SQL statement. Your Rank column does just this.
All I did was to change the correlation of it to your outer (main)
query to rely on the product column being the same for each count
made.

I'm not too sure about the exact syntax you need. If you have any
problem, please post the entire SQL of your query here, not just the
one column. This may be necessary for me to help make it work
properly.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


How do I create a subquery? Do I place it in my existing query and if so how?

Tom Ellison said:
Dear Mike:

You need to correlate the subquery on product:

Rank: (Select Count (*) from T:OpportunitiesReport
where T.product = OpportunitiesReport.product
AND [Extended Cost]>[T:OpportunitiesReport1].[Extended Cost]+1)

That is, limit the COUNT() to those with the same product value.

Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts


I'm trying to rank row in a query. I want to get the top 25 for each product
based on dollars.
e.i.

product sales rank
apples 10.00 1
apples 11.00 2
oranges 10.00 1
Bananas 10.00 1
Bananas 11.00 2

etc.

I'm using the following expression:
Rank: (Select Count (*) from T:OpportunitiesReport where [Extended
Cost]>[T:OpportunitiesReport1].[Extended Cost]+1;)

and can not figure our how to restart the count for each new product in the
query.

Can some on help me?
 

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

Top